.NET is a software framework supporting a multi-language paradigm and supporting language interoperability. .NET applications are executed in a virtual machine (CLR) which provides a few important services: security, memory management and exception handling.

learn more… | top users | synonyms

8
votes
4answers
506 views

Repetitive code driving me crazy!

Ok, So first I must say that everything I know about coding I have learned on my own in my spare time so bear with me if my code is primitive, but please, I am open to any comments to make me ...
1
vote
4answers
104 views

Simple multi-threading class: Does anybody spot potential lock-based concurrency issues?

Trying to write a multi-threaded utility that logs some audit trails to the DB every 30 minutes, or whenever my storage data structure (a list in this case) exceeds a certain limit. The code works ...
1
vote
0answers
44 views

Reusing thread and UdpClient for sending and receiving on same port

The working and functional code below is a simplification of a real test application I've written. It acts as a client which asynchronously sends UDP data from a local endpoint and listens for an ...
0
votes
1answer
49 views

How to optimize response.redirect in ASP.net [closed]

We know when we call HttpContext.Current.Response.Redirect("http://tvrowdy.in"); It throw an exception. Can we do it this way(working fine). Need suggestions and improvements. public static void ...
2
votes
3answers
84 views

What's the most optimal way to see if a string is included in a list of strings?

Something that has bugged me for a while, is what way is best to perform a conditional where a string is compared to other strings. Here is some sample code. This code is just for illustration ...
1
vote
2answers
73 views

Correct way to delete elements from a ConcurrentDictionary with a predicate

I have written a caching wrapper class for ConcurrentDictionary. Basically it has a timer that checks if items are expired and removes them. Since ConcurrentDictionary does not have RemoveAll method ...
0
votes
1answer
22 views

Is this a sensible way to implement a model?

I've created the following model for an academic project, and I'm wondering if this is a sensible way to manage a model: using System; using System.Collections.Generic; using System.Linq; using ...
2
votes
1answer
44 views

A Better Way of Employing a Using Alias Directive

I understand .NET very well until Principals of OOP come into view, so I guess we can say very little. So to work on this, I am making a Console App that will Catalog my Digital Media to a MySQL ...
1
vote
1answer
111 views

Implement recursion

The rules for this program are to: Generate n X n grid. Arbitrarily pick a point and grow a 'shape' based off that initial point. Must have at least 3 points. Strongly biased to not completely fill ...
4
votes
5answers
233 views

Is this an acceptable method name?

GetCollectionWhereKeyStartsWith(string key) The intent of the method is to retrieve a sub-collecteion from a name value collection where the key starts with the passes key argument.
1
vote
1answer
90 views

REST-ish API Account Controller - how's it look?

I still have to implement api keys for client auth, but so far this is what I have for users. This was built using WebAPI and SimpleMembership with Forms Auth: Is Authenticated: public class ...
0
votes
0answers
91 views

Improve my reactive code (ping/pong sample)

I'm starting with the reactive framework, how can I improve my logic? The way it is doing the code below, I can not add parameters in the composition, e.g.: Where, Syncronize, OnError.. How can I ...
5
votes
2answers
98 views

Extension methods for methods and properties that don't use non-public data

Generally speaking, I try and write my classes so they are highly cohesive. Sometimes I have accessors (this problem isn't limited to accessors) which derive their value from non-public data only, ...
0
votes
1answer
63 views

Format A TimeSpan With Years

I have a class with 2 date properties: FirstDay and LastDay. LastDay is nullable. I would like to generate a string in the format of "x year(s) y day(s)". If the total years are less than 1, I ...
-1
votes
2answers
129 views

Insert to datagridview when SELECT query has WHERE condition [closed]

I use this code to Load and Insert data to a table using a DataGridView in a C# windows application. SqlCommand sCommand; SqlDataAdapter sAdapter; SqlCommandBuilder sBuilder; ...
1
vote
1answer
28 views

Caching XmlSerializer in AppDomain

To work around the XmlSerializer memory leak thing I created this: public static class XmlSerializerCache { public static XmlSerializer GetXmlSerializer(Type type, XmlRootAttribute xmlRoot) { ...
2
votes
1answer
123 views

Is there a more elegant way to rewrite this piece of code?

This is what happens, i have a dropdownbox "ActiviteitAardItems" where ActiviteitAard items can be checked (checkbox). If one (or more) are checked the property Opacity will be changed, and the code ...
2
votes
3answers
116 views

Quickly Iterate through 2D array manipulating contained structs

I am hoping to streamline this bit of code better. This snippet does not cause my any slow downs in relation to other parts of the algorithm(?). I would just like guidance on making it better. Some ...
3
votes
1answer
72 views

Encapsulated double for type safety

Link to a full functional solution. I'm working on a physics based algorithm, and I find myself working a lot with functions of style double GetSpeed(double acceleration, double angle, double ...
2
votes
0answers
63 views

pull things from lazy source till timeout is reached

I need to pull things from lazy source till timeout is reached in this fashion: var results = lazySource.SelectMany(item => { //processing goes here }).Pull(timeout: TimeSpan.FromSeconds(5), ...
0
votes
1answer
50 views

Does refactoring a while loop increase CPU usage

While upgrading our code base to take advantage of new features in .Net 4.5, I'm trying to refactor our take of the classic Producer/Consumer algorithm, but I'm concerned my refactoring is going to ...
1
vote
1answer
80 views

How do I shorten my code?

I currently have a huge code for regenerating some things in a game a made. The code is very big and I think it can be compressed but I don't know how to do it. This is the code Private Sub regen() ...
1
vote
1answer
114 views

creating dynamic threads

First, I want to say that this code works, but I want to make sure this is the right way of doing it. I am writing this for a SMS text API that loops through each phone number. I sometimes gets hung ...
6
votes
2answers
136 views

Left hand search in string

the requirement for our search query is to look for all search words in the beginning of vehicle manufacturer, model and variant name. Case insensitive. The word being a string of characters separated ...
5
votes
2answers
214 views

Better way to write the following code?

Is there a better, more elegant solution to the following method? Boolean[] spades = new Boolean[10]; // 40 cards deck foreach (Card card in m_Cards.Where(card => (card.Suit == Suit.Spades))) ...
3
votes
0answers
72 views

Injecting SelectList objects into ViewData to enable using EditorFor on dropdown based properties?

I have developed a system whereby I use an attribute to state which SelectList to use for an 'FK' property. I would appreciate some feedback mainly on by good practice, and also on any ways to do this ...
0
votes
1answer
123 views

Asynchronous version of AutoResetEvent

This is my second attempt to create asynchronous version of AutoResetEvent. At first I tried to make it completely lock-less, but it turned out to be impossible. This implementation contains a lock ...
1
vote
1answer
72 views

Will this converstion to/from fixed point cause me to lose precision?

I have a situation where I have a fixed point number that I want to convert to and from a floating point number. Specifically it is the SANE_Fixed type from the SANE API. Here is the what the ...
6
votes
1answer
104 views

AutoResetEventAsync, am I missing something?

So I wrote an asynchronous version of AutoResetEvent: public sealed class AutoResetEventAsync { private readonly Task<bool> falseResult = Task.FromResult(false); private readonly ...
2
votes
1answer
88 views

Child/Parent relationship by adding an element to list

I have to implement a class with has parent and child fields. The problem is that by adding a child it must immediately keep reference to its' parent. I implemented it and it seems to work but I am ...
2
votes
2answers
211 views

Improving the way a C# application communicates with a SQL database (Via SqlConnection)

*Originally posted this on stackoverflow but was told that it would be better suited here. So I'm looking for a better way to setup how an application talks with a database. I'm sure this question ...
1
vote
4answers
137 views

Understanding Interface

//program.cs class Program { static void Main(string[] args) { Dog oDog = new Dog(); Console.WriteLine(oDog.Cry()); Cat oCat = new Cat(); ...
0
votes
1answer
132 views

How can I implement the generic repository pattern and improve the performance for the code below?

I've used EF-DB first approach and have written a simple app to retrieve the data from the database and show it in the view. The code is simple and ok for a beginner like me, but how can I implement ...
3
votes
5answers
391 views

New to TDD, am I doing everything right? How could I improve?

I'm new to TDD, never used it ever. I understand the basic concepts but I'm now working on a small project which will be the first time I've ever actually used TDD. The code is pretty self ...
1
vote
1answer
52 views

Creating a new item or updating an existing item

Something about my code just doesn't seem right. It feels cumbersome and not very logical. Could someone put me out of my misery and let me know that I wrote this bit ok? It's pretty simple, when ...
1
vote
1answer
364 views

Use and Understanding of async/await in .NET 4.5 +

All, please take the following example code CancellationTokenSource cancelSource; // Mark the event handler with async so you can use await in it. private async void StartButton_Click(object ...
3
votes
3answers
117 views

Cached empty collections

I often find myself in need to create empty collections. One of those days several years ago, I wrote something like the following to address that: public static class Array<T> { // As a ...
0
votes
3answers
81 views

RLE encoding/decoding tool, review source

I've developed mini utility, the source code can get reviewed here: http://rle.codeplex.com/SourceControl/BrowseLatest It's developed in C#, in the general page there is a description. I'm listening ...
3
votes
2answers
165 views

Improving UI response times by threading, a better way?

Since I've started to use a computer, I hated everytime an application's UI stops responding for a while. However, there are some applications I see, that are doing their "heavy" jobs, yet the UI ...
3
votes
5answers
585 views

Faster way of reading csv to grid

I have following in Windows Forms .NET 3.5 It works fine for csv with records less than 10,000 but is slower for records above 30,000. Input csv file can can any records between 1 - 1,00,000 records ...
1
vote
1answer
199 views

Using delegates to communicate between forms and networkcommunicator class

I'm trying to develop an application in c# i currently have a code similar to the one attached below. Basically what it does is: Having multiple form, each of which would like to send message through ...
3
votes
2answers
162 views

Please review my UNC path exists monitor

This is my first attempt at trying to write a "monitor" class to determine if a UNC path is available. I need the monitor to not block the main thread and to also event when the UNC is toggled UP/DOWN ...
3
votes
1answer
2k views

C# Async Socket Server with Events

I have written the following code, I am quite new to C# and Sockets, so perhaps I have made some big mistakes that only more experienced eyes can detect. This is to be used in a Windows Mobile 6.1 ...
0
votes
1answer
83 views

POCO helper class refactoring

I have a helper class that I am using to return the selected items in a number of IEnumerable POCO collection but I'm not happy with the implementation. One of the reasons for using this method is ...
2
votes
1answer
96 views

Create path to file under 64-bit %programfiles% from 32-bit process

I have a process that runs as 32-bits regardless of the architecture. In it, I want to be able to spawn a process from the 64-bit program files menu (e.g. c:\program files instead of c:\program files ...
1
vote
1answer
66 views

Inherit SortedDictionary - Is this good programming practice?

Also posted on Stack Overflow As an example, suppose I had a large amount of data about a set of Restaurants for a large set of Dates in a database that I need to analyze / output to the user. So, ...
4
votes
6answers
450 views

Strategy for avoiding threadpool starvation while performing cpu bound jobs in a queued fashion

My aim is to avoid using threadpool threads for CPU bound work, thus avoiding a situation where IIS stops responding to new requests. Can you see any problems with the code below? Is this a ...
1
vote
1answer
90 views

Improve and adding new method to GenericDataAccess?

I have this GenericDataAccess class to interact with database from my school just I want to ask for some suggestions and advice in how to to improve it and add new methods to for future use & ...
5
votes
3answers
235 views

Are 2 streams really needed?

I have a simple text file setup as a Resource through my application's Properties as a byte[]. In order to access a "Stream.ReadLine" function, I believe I need to make it into a StreamReader. Is ...
0
votes
1answer
74 views

Wraper for caching methods in ASP .Net?

I have written a caching wrapper method for some of my services. The actual wrapper method is written as follows: public T GetFromCache<T>(string key, Func<T> defaultValuePredicate, ...

1 2 3 4 5