.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

0
votes
1answer
8 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
90 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
907 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 ...
7
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 ...
1
vote
0answers
44 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
104 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
61 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
60 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
82 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
83 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 ...
7
votes
1answer
241 views

Somewhat esoteric if statement in a paginated feed

I am working on the home page of a website that will have a paginated feed (much like a blog's home page). One of the requirements is that when a user navigates to a non-existent page, he or she will ...
10
votes
2answers
213 views

Set desktop background

I created a simple program that downloads an image (different image every day), then sets it as my desktop background. I feel like the lines of code can be cut down significantly while still remaining ...
6
votes
1answer
159 views

Reducing memory footprint of ReportViewer

We have implemented a process using C# and ReportViewer to create PDFs by the LocalReport.Render method. When we have to process ...
6
votes
3answers
237 views

Throwing exceptions when validation fails

When I want to check the validity of an attendance being entered into the system, I perform following action. AttendancePresenter Class ...
6
votes
5answers
355 views

Transaction handling for multiple SQL statements

In this code I update two tables called Payment and SalaryTrans. First I insert records (Salary payments) to ...
3
votes
2answers
49 views

Implementing WCF method that supports either string or object as a method parameter

I have the following contract in a WCF-based web service: public List<string> GetAllPossibleQueryEngineHostNames(Instance instance); Obviously, I can call ...
1
vote
1answer
70 views

Access View from current/corresponding ViewModel

Sometimes when developing a WPF application, I need to access a certain Window (View) from the corresponding ...
1
vote
1answer
67 views

Async function with slow web reference(web service) slowing down webpage

Is there a way to make a threading/async post with a web reference not slow down the whole website just because the web reference takes a long time to return a response? I have a send email function ...
3
votes
1answer
62 views

Data Access Layer method with transaction handling

I just want to know whether I've done transaction handling well. Also what about the other types of transactions available in .NET with regard to this code snippet? Also are there any redundant ...
1
vote
1answer
68 views

Returning information about the result of a file processing, without using output parameters [closed]

As part of a C# class CsvConverter that converts various file types to CSV, I am designing a private class CsvConversionResult. ...
3
votes
1answer
84 views

Reduce logic in Web API controller

I have the following scenario - i have a grid on web page that is populated with data. User can check a check-boxes in grid and data is saved to DB on navigating to next page. If they then navigate ...
3
votes
3answers
144 views

Binary addition with strings

The following method will add two strings of any length as binary numbers assuming the characters 1 and 0. I made this for fun ...
1
vote
1answer
75 views

improve performance of recursive function in c# method

I'm trying to write a function which will cache objects in memory. The function below works, but performance is unbearable. What would you recommend to improve performance? ...
2
votes
1answer
67 views

Validation invoking queries?

I have a question regarding whether it is viable or deemed correct if a validation object invoked a query. Essentially, I have some code that looks like this: ...
3
votes
2answers
104 views

HttpRequest.Json collection - like HttpRequest.Form

I'm looking for a code correctness and best practices review on the following. I created the following in order to prevent using the same code to convert serialized JSON to something more accessible ...
2
votes
0answers
45 views

Resolve (domainless) machine name from DNS alias

So I have a URI with a DNS alias, and I need to I need to dynamically replace the alias with the actual machine. I started out with this: ...
4
votes
2answers
69 views

User Authentication Bundle

I wrote a user authentication program(s) for an MVC application. Before you ask part of the project specs are I have to store user information in company databases on servers that aren't the web ...
2
votes
1answer
39 views

Creating a New User Account

I feel like this maybe to much for one method... This method lives inside of a service class which is called by an interface. It dumps data into three different tables within a database. ...
6
votes
5answers
566 views

Username, Password and UserType Validation

I have two tables in the database: Credentials (userid, password, usertype) Customer ...
5
votes
4answers
233 views

Passing parameters to a query

I have a function that takes a Dictionary<String, Object> as an argument. It uses this Dictionary to create parameters ...
3
votes
1answer
72 views

Populating DataGrids

I'm building an in house query tool. The main form has a drop down which allows the user to select how they want to find scripts, and a drop down for what server they want to run the query on. There ...
7
votes
3answers
122 views

Dataset with optional addition to where statement

I am trying to generate a dataset from a query that has a where statement. If the user passes a value additional things need to be added to the ...
2
votes
1answer
62 views

Avoid redundancy of HTML entities in .NET framework

I have to store various HTML named character references for the following purposes: Escaping special characters myStringBuilder.Replace("À", WebHelper.Agrave) ...
1
vote
1answer
81 views

Update multiple records with Entity Framwork

I am wondering what the best way to update multiple records with Entity Framework is. This is how I normally do it, and it does work: ...
10
votes
4answers
599 views

Find if value exists using SQL True/False Return

Aim: To Assess if one, or more, examples of a value exists in a Database in the quickest time as I only needs a True/False result. The variable is Alphanumeric. Question: Is this the quickest and ...
2
votes
1answer
80 views

Binding data to a ComboBox and then showing ValueMember in another TextBox

I have a comboBox and a TextBox in the View and when the view is loaded, the ...
3
votes
0answers
83 views

Binding a DataGridView to a List

I'm new to Databinding in MVP and I want to bind my DataGridView to a object list. This grid may be populated in two ways. There are TextBoxes in the form and users can enter text, and when they ...
3
votes
1answer
48 views

Optimisation XML handling within vb.net application

I need to optimize this snippet to be faster: ...
23
votes
3answers
3k views

What are the best practices with multithreading in C#?

For a while I have been interested in seeing if some tasks work well when split across multiple threads. On the one project I have been busy with I have been creating a lot of small utility apps, to ...
6
votes
5answers
1k views

Regex validation for Email Address

I need to validate whether my regex is correct for below scenario. Suggestion's if the regex is correct: Wiki Link Local_part The local-part of the email address may use any of these ASCII ...
3
votes
3answers
77 views

Validating a string under few conditions

Following code validates NIC number of a person (National Identity Card, no like SSN) Requirements are... Length should be 10 digits or characters All should be digits except the last one Last one ...
2
votes
1answer
53 views

Using a single validation handler for all controllers in a form

In input validation I'm using this validation method in my all Forms. Here I have a single handler for all TextBoxes in my Form and if I have other controllers like ...
5
votes
2answers
114 views

Convert string to multiline text

I made this method that takes any string and transforms it into a multiline text l; each line having the max (character) length specified by the rowLength ...
3
votes
4answers
265 views

Input validation for text boxes in a Form

In a Win Form I'm doing initial validation in the Form. So before saving data, I want to validate whether all the required fields are filled (Text Boxes) by the user. There are about 18 such Text ...
4
votes
1answer
166 views

IndexOrDefault that functions like FirstOrDefault

I don't know why this is not in the .NET Library, but I need to be able to use an index against a list and not have it throw an exception if it is outside the bounds of the list. This is what I came ...
2
votes
1answer
79 views

Calling a copy constructor in Presenter to prepare a list of Models

I'm new to MVP. In a presenter I have following code. Here what am I trying is to create a list of Model objects (in this case ...
3
votes
1answer
67 views

Exception handling with expression lambda in Presenter class

Following is a code snippet from MVP Win Forms application. My DAL doesn't handle exceptions and it will be propagated up to the calling method in the presenter classes where the exception will be ...
2
votes
0answers
107 views

Possible memory leak with WPF Custom Control?

I might have a potential memory leak with my custom control. Do I actually have one? ...
4
votes
1answer
48 views

Follow Up post: Proper handling of exceptions in MVP

This is a follow up post of my early question "Proper handling of exceptions in MVP" So based on the answers I re edited the post and now my exception handling code looks like this... DAL ...
6
votes
2answers
325 views

Proper handling of exceptions in MVP

In my DAL currently I'm handling exceptions as follows. Is it in an acceptable level? Note : I'm using MVP in this Winforms application. ...