.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

4
votes
3answers
59 views

Conversion helper with support for enumerations and Nullable<T>

I recently wrote this code as a more versatile stand-in for Convert.ChangeType. I have a nagging feeling that there's something I might be overlooking, or that ...
3
votes
1answer
48 views

Event Subscriber with Parallelism

I am trying to exploit asynchronism for parallelism. This is my first attempt at a parallel event subscriber. In your expert opinions, is this a valid approach? ...
-4
votes
1answer
53 views

Declaring the reference of an object within a for loop [on hold]

Please let me know which approach is better and why. Is it better to initialize the variable outside of the loop, or inside? Case 1: ...
3
votes
1answer
33 views

Invoking only the last registered event handler

We are building a game and we have a dialog system. Dialogs may open and stack on top of one another. When every dialog opens, it registers itself to handle the BackButtonPressed event: ...
13
votes
9answers
613 views

How can I refactor to avoid repetition finding the index of strings in a list?

I have a list of strings where I want to find the index of a first- and second-choice video compressor. Logic: If the first choice is available, return its index. If not, and the second choice is ...
2
votes
2answers
68 views

Streamreader file.Readline properly closing the stream

Is this OK? (.Net 4.5) ...
7
votes
1answer
385 views

Math expression parser in C#

EDIT: Added refactored version 2.0 to the end! I have a parser that is supposed to take a string similar to a math expression and return a Tuple of: An array of strings where each string ...
11
votes
1answer
88 views

Change desktop background

I created a simple program that downloads an image (different image every day), then sets it as my desktop background. It is a console application, and closes immediately after downloading the image ...
3
votes
1answer
48 views

Make huge view in C# readable and maintanable

I have an application that is using MVC5 with C# and Razor Engine. This view displays a huge table: ...
1
vote
2answers
75 views

Producer Consumer in C# with multiple (parallel) consumers and no TPL Dataflow [closed]

I am trying to implement producer/consumer pattern with multiple or parallel consumers. I did an implementation but I would like to know how good it is. Can somebody do better? Can any of you spot ...
4
votes
2answers
126 views

Speeding up Parallel.ForEach iterating through datatable and rendering report

I am attempting to speed up the processing of 5000 rows received from the database, which I then render as a crystal report, export to a byte stream and save in a database table. Currently I am using ...
4
votes
1answer
80 views

Asynchronously wait for a task to complete and do some async action while waiting

I have a long-running task. My goal is to create a method that will allow me to: Asynchronously wait for this task to complete While waiting on a task, do some async action once in a while. This ...
0
votes
1answer
63 views

Seekable HTTP Range Stream

I read around for a while and surprisingly didn't find a fitting solution. I need a .NET Stream that internally issues HTTP Range requests when it seeks. There are huge files server-side for which I ...
2
votes
1answer
75 views

Is this the correct usage of ConcurrentDictionary<TKey, TValue>?

I need to make a simple class that tracks how many clients are listening to a specific item, will be referred to as building hence forth. I will have a timer running that will check which buildings ...
3
votes
2answers
209 views

Get missing sequential numbers from array

I have an array like Original = {1, 2, 3, 6, 7, 8, 9, 10, 12}. After removing some elements like Delete = {6, 7} from it, I want ...
0
votes
2answers
151 views

Connecting to a MySQL database with C#

Can anyone help me with checking this code? It is for connecting to a database. The method getFromDatabase is to take values from the database and put it to a ...
4
votes
2answers
141 views

.NET REST API JSON Filtering

My question, REST API and lazy loading objects, didn't receive any answers (or many views), so here is my attempt at the solution. Problem overview: My mobile app requests a list of objects through a ...
3
votes
0answers
35 views

Tuning Excel calculation engine which uses MS Excel interop

I am currently building an Excel calculation engine. It's purpose is basically to wrap the calculation logic of an Excel workbook in order to use the logic from a C# library. ...
10
votes
2answers
158 views

Embedded C# bitpacked arrays to low-level STM32F4 driver for GE G35 RGB LED Christmas tree light

I'm going to be opensourcing some code I'm working on. I don't need help with the code, I just want to make sure my code is readable and my comments make sense. I have a knack for the esoteric. ...
4
votes
2answers
395 views

Code organization for .NET solution

I am going through one of my class library projects, and while nothing is wrong with it, I am finding myself being a bit anal, and wanting to organize things a bit differently. The project in ...
1
vote
1answer
66 views

Work with nested task [closed]

I have Client and Server classes. The Server return a ...
0
votes
0answers
36 views

From multiprocess to multithreading [closed]

I recently joined a team responsible for the enhancement of an existing 5-year old program. It was developed with multithreading in mind, but not correctly implemented. The solution is composed of ...
2
votes
1answer
37 views

Implement interface type in implementation of another interface without too much casting

I have a group of tests that must be run in similar (but different) fashion and they have setups, results, etc. which are also similar but different. Great, I thought, I'll use interfaces to define ...
3
votes
3answers
176 views

ObservableQueue

I'm looking for feedback on this. ...
5
votes
2answers
200 views

Proper usage of “using” statement in base64 encode method

I used the example on here, but with little changes in order to write a base64 encoder method. I have a few points about the code: I would like to use using ...
1
vote
1answer
62 views

Security of ProtectedObject

Is ProtectedObject really secure? Otherwise, do you have any advice? ...
1
vote
2answers
105 views

Logger facade code for configuring multiple loggers are runtime

Following is the code for a logger facade that I have created, which can be used to log via any of the standard and configurable loggers like log4net, BitFactory, currently I have just integrated ...
6
votes
2answers
61 views

Buffering of fast changing datapoints or events

The following class implements a buffer which captures fast changing datapoints or frequently raised events and dispatches them in batches. It will asynchronously call a processing function for the ...
1
vote
1answer
83 views

Performance issue in .NET remoting

I can't understand why this strange behavior when I call the method remotely is expensive. I have observed a performance issue when my object method called remotely compared to when it's called ...
7
votes
3answers
1k views

Replace each whitespace in a string with “%20”

My implementation: ...
3
votes
2answers
136 views

Implementing faster StringBuilder that only works with ASCII strings

I wrote a StringBuilder that works only with ASCII strings. the current append performance is almost identical to BCL StringBuilder append performance. I want some tips on how to make it faster, and ...
2
votes
0answers
63 views

Supporting Enum in EF 5 with .Net 4.0 (Visual Studio 2010)

I'm currently working through Getting Started with EF5 using MVC 4 in Visual Studio 2010 (.NET 4.0) to learn about how to use ASP.NET and Entity Framework. During the beginning of the tutorial I ran ...
5
votes
2answers
90 views

Secure password hashing implementation

I'm implementing a password hashing method for a website. The code below is part of the User class. Any pointers on what I could do better? ...
3
votes
1answer
112 views

Efficiency of nested LINQ foreach loops

I've been working on an older project with framework is 3.5 as the target. There is a new user control that displays a list of data from a web service. I hit the web service (Soap/XML) and deserialize ...
2
votes
1answer
92 views

Implementing ViewModel design pattern using DI in a MVP-VM architecture

Based on this answer: MVVM implementation using C# and XAML, I understand that my ViewModel is some kind of a wrapper for my Model. Being a fan of DI and SOLID principles, I have made my ViewModel ...
4
votes
2answers
52 views

Determining if a discount is valid for a product

I'm in the process of re-writing a method I've come across in our code base. It's pretty lengthy and a lot of it seemed redundant. It's a Discount object class ...
10
votes
5answers
863 views

Is this Repository Design Pattern Valid and efficient?

I am using Dapper ORM in my Data access Layer, but I think analysis of the code below doesn't depend upon any specific ORM. What should be the single common place throughout the entire Data Access ...
4
votes
2answers
72 views

WCF service implementation

I have WCF Service using .NET 4.0. I have similar methods, similar code and I want use good patterns for improvement the code for get high level quality. I want reuse code, maybe using ...
5
votes
1answer
190 views

Reading large file, splitting by new line

I am reading a ~120 MB log file (~300 Million lines of text). ...
2
votes
2answers
264 views
2
votes
2answers
107 views

Idiomatic and Conventional F#

As of late I have been learning F#. Today I accumulated what I have learned so far to develop my first program - a script that counts the number of lines of code in a given Visual Studio project. ...
5
votes
1answer
140 views

Optimizing FirstOrDefault

I'm working on an application in which it takes quite a bit of time to initialize the data. Some background: I'm creating a sort of pivot table in which I turn Figure 1 below into Figure 2. I've ...
10
votes
5answers
960 views

Using TryXXX pattern to avoid exceptions

I have been using the TryXXX and GetXXX pattern lately to give clients a choice whether to trap an exception or to read a boolean. An example of this concept would be ...
8
votes
5answers
2k views

One-shot events in C#

I have a class that performs some long-running operation. This class exposes a Completed event. I'd like clients that use this class to register to get notified ONLY ONCE when the class completes ...
5
votes
1answer
88 views

Separation of concerns for security checks

I needed a nice typesafe way to implement security checks for various domain objects and actions that can be performed on them. I had an idea how to do it, so I implemented it as a simple proof of ...
4
votes
1answer
278 views

Creating Thread safe list using Lock object

Will this code qualify for a truly thread safe list? It is using the Lock object. ...
1
vote
1answer
269 views

Creating Thread Safe or Concurrent List [closed]

Can a thread safe or concurrent list be created using the code mentioned underneath, where I wrap all the calls to the base class in a ReaderWriter lock. I can similarly implement all the public ...
5
votes
1answer
88 views

Renaming numbered files for proper sorting

I have designed a tool that generates some HTML files and a CSS file in a directory, which then feed into a tool called Jutoh that uses these to make eBooks. However, my output files are of the form ...
5
votes
1answer
94 views

Iterate through dynamic levels [closed]

I have the below function that works and cycles through 3 possible levels. Is there a way to do the same as the function below but not have to do the multiple ...
4
votes
1answer
89 views

Unusual comparison of object and string

I have a pretty unusual situation (please, don't ask why) where I need to compare objects which might be a string or double to ...