Questions tagged [.net]

.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.

Filter by
Sorted by
Tagged with
5
votes
4answers
6k views

Presenting a boolean as an int for XMLSerialization in C#

I'm working with an XML structure that requires booleans to be represented as 1 or 0. So, suppose the XML output has to look like: <valid>1</valid> ...
5
votes
2answers
424 views

Retrieving data based upon text entered in a textbox

I have two text boxes and one combobox. I am retrieving the data based upon the text entered into the text boxes and combobox selection, by using the following method: ...
3
votes
1answer
7k views

Image processing optimization

I'm using Winforms C# .NET 3.5. I'm getting frames, and this is how I handle them: ...
1
vote
1answer
2k views

Custom timer code needs reviewing for thread safety

I've created a custom timer to satisfy the following requirements: Millisecond accuracy I want the tick event handler to only be called once the current tick handler has completed (much like the ...
2
votes
1answer
2k views

Optimization of region of interest (ROI) drawing in the image

I'm drawing rectangular ROI region by darkening the area outside of it as in this image: But image.MakeTransparent takes too much time. What is the best way to ...
3
votes
1answer
12k views

Selecting a specific row with a desired value

I am trying to get a row if it has the desired specific value, otherwise get the first or default: ...
8
votes
1answer
366 views

Using Delegates and BeginInvoke with .NET 2.0 WebServices

I'm attempting to implement a simple long-polling/comet/reverse AJAX solution, and came across the concept of delegates, specifically with the BeginInvoke and ...
5
votes
3answers
218 views

Issue a redirect, trying several string replacements for the domain

How could I improve this code? ...
4
votes
3answers
1k views

Guarantee at least one in a list

This is a short piece of code but I feel like it could be done more elegantly. What am I missing? The goal: if there are any items in a list, and none of them have a given property, set one of them ...
10
votes
1answer
23k views

Converting binary value from BitArray to an int and back in C#

What I am creating is essentially a binary clock face with touch input for setting values as well as displaying - so I need to convert both ways between an int and a binary sequence in a BitArray. I ...
7
votes
6answers
11k views

Place try/catch in business logic or user interface

I found the following two types of exception-handling in Business Logic Layer. ASP.NET 3.5 Enterprise Application Development uses a similar method like the first one (I read it few years ago). I ...
3
votes
2answers
141 views

Subclassing, NVI

Should the following be considered wtf code? ...
3
votes
1answer
245 views

Is there any loss in performance converting a 'where' clause to a lambda?

Is there any different in performance for the following 2 queries. I'm just wondering what is the better of the two: ...
2
votes
1answer
930 views

Use of Ninject and an injectable DataLayer in MVC3

I'm trying to make an MVC3 application with an exchangeable data layer. I currently have this in a single file (Global.asax.cs) for brievity. It seems to be working as I want but as I'm new to DI I ...
5
votes
4answers
1k views

Persist data by serializing/deserializing objects that are sent to it

I've created the following class to persist data by serializing/deserializing objects that are sent to it. I would like to know if there is a better way of writing this class, or if my class is fine ...
7
votes
3answers
1k views

3-layer ASP.NET app - Need critique/advice

My current setup is a 3 layered application: UI > BLL > DAL. Each layer is set up as a separate project. The UI is an ASP.Net website and the BLL & DAL are Class Library projects. I've shown some ...
5
votes
2answers
2k views

Strategy Pattern for Oracle Database?

I'm trying to implement the Strategy Pattern into my current code base. I would like to know if i'm going in the right direction on this? IOracleDB.cs: ...
11
votes
2answers
31k views

Insert multiple rows into a SQL table

I've written the following C# code to insert rows (that a user enters from a web application) into a SQL database. How does this code look? Is there a better, more efficient way to accomplish the ...
5
votes
1answer
974 views

Processing a webpage source

I have developed a test app that works by getting webpages source and processing it. I have up to 100k URLs in queue and want to use a maximum of 25 threads. Please help me check if the code is good ...
4
votes
2answers
958 views

Is this a good way to handle Web API UriTemplates?

I want to be able to do /contacts/Matt%20Phillips and /contacts/1 and have both of them return a contact. The way I did that was ...
3
votes
1answer
888 views

How to improve execution of web service using System.DirectoryServies.AccountManagement that runs very slow?

This method runs in just under two minutes. I would like to optimize it to run in less than 15 seconds. Using a LAMDA filter on my list before iterating it's elements and removing one conditional ...
2
votes
1answer
450 views

Simple search page.

...
5
votes
1answer
1k views

Trying to un-hack this DataTemplateSelector

I'm trying to emulate the default behavior of an ItemsControl in a ContentControl--Bind Content to an object property and use the correct DataTemplate based on that ...
14
votes
6answers
3k views

Showing various network information from a NIC card

I have included the code from a second year project that I would like some advice on. Basically it utilises WMI to query a NIC card from a selection (depending how many are installed in the host ...
3
votes
1answer
258 views

C in CRUD for Silverlight

The C in CRUD Silverlight: Create new Silverlight business application "CRUD" Add ADO.NET Entity Data Model to CRUD.web Select the db, the tables, build the project Add Domain Service Class to CRUD....
33
votes
6answers
4k views

DisposableObject base class for C#

I commonly run into the need to implement IDisposable in my code. To correctly dispose of both managed and unmanaged resources requires a reasonable amount of boilerplate code. Based on the ...
6
votes
2answers
7k views

Unit (Integration) Test for code that interacts with a database

I am trying to create some (I believe these are Integration not Unit) tests for code that interacts with a database and I am not sure this is the right approach. I would appreciate any reviews and ...
8
votes
1answer
3k views

Database Class Creator

Overview I've written a class that will create C# code. The output is a single .cs file for each table in the default database (the database is defined inside a web.config file). I'm looking for a ...
5
votes
2answers
9k views

Database access class

I'm looking for any comments or feedback on my database access class. Security and speed are two things I'm most concerned about. One thing to note is this class has to work in a C# .NET 2 ...
12
votes
1answer
591 views

Utility functions for supporting memoization for functions

I've got a couple of utility functions to support memoization for functions with anywhere between 0 to 8 arguments: ...
6
votes
4answers
6k views

Function to test if the current time is within a time window

I have written the following code that tests if the current time is within a time window. It seems to work ok with my test cases, but I would be interested if anyone can see any possible problems or ...
4
votes
4answers
475 views

Comment formatter

...
9
votes
2answers
3k views

Async Task implementation

Beeing on .NET 3.5 i don't have access to the TPL. Yet i have become fed up of having to manage manually the logic behind delegate.BeginInvoke type of scenarios each time and i set up to implement my ...
3
votes
1answer
236 views

Refactor a subroutine that divides date range into quarters.

The subroutine below, GetDetailsQuarterly, accepts two dates. Then it writes out each quarter that falls within the date range. It also gives the first and last day of the quarter. I really don't like ...
7
votes
2answers
32k views

Is there a better way to search directories for a file or files?

Edit: The purpose of this method is to search a specific directory for a given file type, ex. (*.txt, *.pdb, *.exe") then move the file(s) to a given destination directory and delete the original ...
5
votes
1answer
4k views

Why is this code to paste into a DataGridView so slow?

...
11
votes
3answers
7k views

Searching a sequence for a pattern

I have written the following tiny extension method to help me when I'm working with sequences in which I have to find a pattern. ...
19
votes
3answers
8k views

scoped_ptr for C++/CLI (ensure managed object properly frees owned native object)

Motivating SO question: Is there a C++/CLI smart pointer project (e.g. scoped_ptr)? I'm interested in any reviewer comments, and especially identified bugs or inconsistencies with the native ...
10
votes
2answers
608 views

Left join query of user profiles

I have the following left join LINQ query that is returning the results that I expect, but it does not "feel" right. I need ALL records from the UserProfile table. ...
7
votes
3answers
4k views

ThreadSafeObservableCollection of (T)

The idea here is to implement a simple, threadsafe, observable collection that clients can bind to, whilst background threads can update. Changes in the contained items raise the ...
4
votes
1answer
508 views

WebMethod slower on execution than Windows application of the same code

I have developed an application that interacts with IBM ClearQuest. The problem is that when I run everything locally, such as, run the webservice local and then ASP page local, everything is at the ...
6
votes
2answers
3k views

Best practice instantiating generic delegates and accessing property getters

I want to create delegates to access properties of different objects without knowing them in advance. I have the following definitions ...
3
votes
1answer
723 views

Retrieving context menus from the form

I have the following code which is a private method inside the form and retrieve all context menus from the form. I feel, that it is not that concise as it should be. Would be grateful for any ...
11
votes
2answers
22k views

Mapping ExpandoObject to another object type

I am working on a helper method that maps properties from an ExpandoObject to a user supplied object and was wondering if the code could be cleaned up or made any ...
6
votes
2answers
6k views

Recursive database actions

I am been using a code pattern for recursive database actions in my applications. I create two class objects of a database table, singular one (e.g Agent) for holding single record with all fields ...
8
votes
7answers
1k views

Refactoring a bunch of and statements

Trying to refactor this code and can't seem to think of a way to make it cleaner. Type is a property in my Person class. ...
11
votes
5answers
7k views

Deep nesting when looping over an object model coming from a 3rd part

I am stuck with this horrible object model coming back from a 3rd party product. It's six levels of objects deep, and I have to loop through the collection in each level, to get the values I need, in ...
7
votes
2answers
4k views

Automatic translation of forms

I want my application to support multiple UI-languages (aka i18n). To do so, I have built the static class below, to automatically translate the form and all its contents to the desired language. It ...
11
votes
5answers
8k views

Nested if statements with 3 different parameters

I have a block of code below. The allDone() method at the bottom should only be run if the allCompleted == true. It should run ...
10
votes
1answer
513 views

Getting the last date where a given week day occurred

I'm trying to learn a little bit about functional programming and as my tool I chose F# since I'm a .NET developer and the environment is more natural to me. In one of my pet projects I'm dealing ...