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
4
votes
1answer
221 views

Generic class for Unit of Work pattern

In my project I use the Unit of Work pattern and it works really well. The implementation is the following: ...
4
votes
1answer
1k views

Running a collection of BackgroundWorkers one after the other

In my project, I had three BackgroundWorkers that can be run independently, but I also wanted to allow the user to "Run All" of them, but not at the same time. They ...
1
vote
2answers
80 views

String to class variable initializer

I have a piece of code that takes a string array with 'key/value' pairs split with a ';' and finds the type of each variable and initializes the variable to the value given. The code given works as ...
5
votes
1answer
707 views

Parsing a string using a regex and doing a mathematical calculation if there is a match

This is my first time writing anything in C#/.NET. I have written a simple function that takes a string, splits it, compares each split value with a regex and if it matches it'll take the second part ...
2
votes
1answer
488 views

Quest System in C#

I have created a quest system for a sort of game. The users will be able to complete quests by doing simple things and in return earn rewards for completing them. Handles everything quest related <...
3
votes
1answer
117 views

Group System in C#

I wondered if someone could give me some constructive criticism on my group system? Holds the badge parts for groups. ...
1
vote
2answers
108 views

Slowed Data reader in C# [closed]

I am writing code to update data in the sample table (i.e. stbl) atoms of a video/audio file and found that in my method UpdateValues slows down to almost a crawl ...
3
votes
1answer
4k views

Updating WPF image from camera frame grabber thread

I have created a WPF application in .NET 4.6.1. to display video from the frame grabbing event for a machine vision camera. In XAML there is an image control bound to a WriteableBitmap ...
5
votes
1answer
7k views

Factory pattern along with DI using Unity container

I am learning design patterns and this is my sample code where I have implemented Factory pattern and instance creation I have delegated to Unity container Framework(DI) to build the loosely coupled ...
8
votes
2answers
5k views

Copy a similar list to another

My code works fine and I am just wondering is there a more efficient way to copy a similar list to another and ignore the properties which are not present. ...
9
votes
1answer
2k views

ResettableLazy<T>: a resettable version of .NET Lazy<T>

I implemented a resettable version of .NET Lazy (context: mostly to use it in a MemoryCache for auto refresh purposes on item expiration) This is a very naive implementation and I am pretty sure ...
1
vote
0answers
83 views

Thread-safe hashset that enumerates according to insertion order

According to the .NET documentation, HashSet<T> does not maintain order when enumerated so I implemented my own using F#. Can anyone help review if this is ...
1
vote
1answer
150 views

How to combine items in List<string> to make new items efficiently

I have a case where I have the name of an object, and a bunch of file names. I need to match the correct file name with the object. The file name can contain numbers and words, separated by either ...
1
vote
0answers
1k views

Cancel running Task on Dispose and race condition

I'm building a wrapper around NamedPipeServerStream and NamedPipeClientStream. Currently my ...
1
vote
1answer
775 views

Generate c# classes through XSD.exe automatically based on embedded resources in assembly

This program is supposed to take every embedded XML Schema file in an assembly and generate classes in the csOutPath. The names of the classes and files should match the stored schema and be put in ...
4
votes
4answers
13k views

Get the brightest rectangle within an image

I wrote an extension method for bitmaps which finds the brightest rectangle (with specified width & height) within an image. Hopefully my code comments eliminate any confusion. If not, please let ...
3
votes
1answer
72 views

Subscription handler

I have so many classes like this in my solution but I've chosen this one just to show you guys what I mean by it. In my solution I have lots of classes that just follow the same 2 classes exactly the ...
6
votes
1answer
3k views

Concurrent HashSet

I've recently been using HashSet and locking on each method, I found this to not only be a lot of work (was using it in a lot of places) but I started to see inconsistency in my code. I later decided ...
1
vote
0answers
177 views

RSA Encryption, improving programming practice and code quality?

This was my first go at any kind of encryption in any kind of programming aspect but my application needed some kind of RSA end encryption for my game packets. Uses RSA and diffihelman and runs off 3 ...
1
vote
0answers
80 views

C#: Foreach vs Seperate Threads?

Each 'Room' class instance needs to call the method 'ProcessRoom'. I am currently overthinking something and would like another persons opinion. One of the constant things here is ProcessRoom gets ...
1
vote
0answers
67 views

Task/Thread/Timer Dilema

I'm looking to improve the performance, quality and effiency of the following code. I have a server I use for my game that manages all the players connected plus a few other things, which have Manager ...
1
vote
1answer
126 views

Managing player data

Here is a code example from my name, where I use a MySQL db and store players data. In this code I'm using a DataReader when loading and saving the data in and out....
2
votes
2answers
2k views

SqlCommand ExecuteReaderAsync helper method

The following helper method executes commands asynchronously and returns a Task<IEnumerable<T>> where T is a type that receives the row information from ...
1
vote
0answers
435 views

KDF computation using CMAC with AES (as PRF) using Bouncy Castle C# library

Using bouncy castle .net implementation (version: 1.8.1.0), I am trying to create an encryption key from a known master key using a key derivation function. The NIST Publication 800-108 contains ...
1
vote
0answers
75 views

Loop through records, change property of records, send mail for each

I am trying to basically do the following Get record from db. Loop through records and send mail out for each record. Update database records. I would like to know what is the most optimal way to do ...
2
votes
0answers
228 views

Customizable Blockchain's block structure

I'm creating a new open-source blockchain framework for .NET Core and .NET Standard. But I have some questions about how to make block structure to be customizable and look beautiful. Let's begin ...
1
vote
0answers
56 views

The Login Authentication Model Class for ApiController

This class accepts input parameters (Login and Password) from ApiController via ...
4
votes
1answer
123 views

Rare binary numbers

Rare numbers are the natural numbers in their binary forms in which there aren't two (or more) ones next to each other. Make a program that will give the N. rare number! For example: In case of N =...
2
votes
2answers
1k views

C# Extending the DispatcherTimer - Intermission timer

I'm working on a WPF project where a timer with Pause/Resume functionality is required. The standard Windows.Threading.DispatcherTimer doesn't offer that, so I ...
-1
votes
2answers
3k views

Set Label content and make it disappear after 5 seconds

Let's say I have a label and a button. If I click the button, the label is set to some text, say "hello, world!", and after 5 seconds, it should disappear. Easy enough, right? I have the following ...
2
votes
1answer
654 views

Creating a shortcut class in C#

I'm working on making a shortcut... manager, if you will. It will be reused throughout the rest of the application for registering types that can later be resolved into views. I have a rule that the ...
2
votes
0answers
312 views

Extension methods with reusable logic - passing Action to Func<TResponse>

I have several extension methods for interacting with the Google Calendar API, and these all use an ExecuteWithRetry function for wrapping API calls within retry ...
15
votes
6answers
14k views

Determine if an image is opaque or transparent

I wrote an extension method defined for the Image Class (System.Drawing) — which returns a Boolean value telling you if the image is opaque or transparent. The color of each pixel in the image is ...
1
vote
3answers
2k views

Simple web service call with retries

This code is actually pretty basic. Basically, I'm doing a large number of web calls. I currently do up to 3 Web Service calls simultaneously, one of which is below. There were 3 errors I saw in ...
2
votes
2answers
104 views

Multiplying/Dividing before Adding/Subtracting

I'm working on a calculator for educational purposes and was asked to include a rule that multiplies/divides before it adds/subtracts. Let's assume I have the following equation ...
2
votes
0answers
917 views

Adding support of HTTP PATCH

I have an API endpoint to modify a race car, which supports the PUT method: PUT /api/racecars/{racecarId} Since PUT must be ...
3
votes
2answers
147 views

Getting a serial number from shared table

I have a table that keeps track of a global serial number shared between several tables. This is not the PK or unique id for each table. It is like a case identifier. Every time users create a new ...
2
votes
1answer
536 views

TPL Task tracker which keeps track of tasks

This class keeps track of tasks which are added and tries to remove them after certain delay. I tried doing it with CustomTaskScheduler but didn't get much in return. Here is my related question on ...
5
votes
1answer
4k views

Generate video thumbnail

I wrote a simple, yet disgusting video thumbnail image generator method—which uses the MediaToolkit .NET library. The code is not self-explanatory whatsoever, and it's extremely inefficient. It ...
4
votes
3answers
392 views

Parse a stream of space separated numbers

I need to parse a stream of characters IEnumerable<char> as a list of space (and newline) separated numbers. Numbers can be expressed in base 10, base 8 (...
1
vote
0answers
1k views

HTTP PATCH method for WebAPI

I'm working on an implementation of the HTTP PATCH method for WebAPI. I know there are packages like JsonPatch and OData Delta for that, but they don’t work for me. JsonPatch is too complicated and ...
6
votes
2answers
483 views

Validate a password mostly to NIST-2017 standards

I have an application that needs to validate user passwords to a very reasonable custom validator, which is heavily based on NIST-2017 requirements. The validator intends to satisfy the following ...
1
vote
2answers
493 views

Common Sorting Algorithms

Here I've prepared my solutions for the following algorithms, and was curious if there were a way to optimize any of them. Any input is welcome and appreciated! ...
2
votes
1answer
71 views

Generating different numeric sequence based on user input

I have the following task at hand and I have completed it and it is working fine. Since I am new to design patterns, I would like to take your opinions on how I can improve the code quality in terms ...
2
votes
0answers
507 views

C# FileSystemWatcher Manager with Debounce

For a class last fall I was working on a "cloud backup" system. Originally in Pascal, I decided to rewrite it in C# and expand the feature set. Below is the FileSystemWatcher "manager" class which ...
0
votes
0answers
49 views

Extract value from a database and populate objects

I have a database, with some history data for a lot of tags (ie. measurement points in the plant). Users supply a calculation script, and get the result of the calculation as a result. The main ...
2
votes
1answer
176 views

Building a very basic calculator

I have been a VB developer for couple of years, but strictly using functional programming paradigms — I just started using object-oriented paradigms a few days ago, and want some advice on how ...
3
votes
1answer
145 views

Exposing .NET's internal StorageRoot via Reflection for accessing file/stream-based Structured Storage

.NET tantalizingly exposes StorageInfo and StreamInfo as public classes, but hides the ...
5
votes
1answer
5k views

Encrypt and decrypt a message using AES-256 with GCM mode using Bouncy Castle C# library

Goal: Given a plaintext message and 256 bit key, encrypt (and subsequently decrypt) the message using a 12 byte IV (in this case null bytes for simplicity, should not do this, I know) with MAC of ...
4
votes
1answer
131 views

Binary search for a missing or default value by a given formula

An application I've been working on for a while needs a manner to find a missing element from a sorted array, the problem with the application is that these values aren't numeric. They have a formula, ...