C# is a multiparadigm, managed, garbage-collected, object-oriented programming language created by Microsoft in conjunction with the .NET platform.
5
votes
3answers
44 views
Thread overkill with async/await
Consider the following code.
public async void Connect()
{
bool success = await ConnectAsync();
if (success) NotifyUserOfSuccess();
}
public async Task<bool> ConnectAsync()
{
var t = ...
3
votes
1answer
35 views
Refactoring a method that binds data to a TreeView
All the flow depends on parameters. It's all in same method with an if else...but I want to make the code a bit more clear. How can I functionally decompose this method into many?
private void ...
-1
votes
0answers
30 views
A generic Re-usable C# Property Parser utility [on hold]
This is about a utility I wrote, which can parse through the properties of a data contracts at runtime using reflection. The input required is a look-alike XPath string. Since this is using ...
1
vote
0answers
40 views
Asynchronous Server Sockets - Thread-Safety/Performance (MMO Gaming)
I'm writing this game server for my small 2D MMO game.
So here are my questions:
What do you think about the Thread-Safety of the code?
Please explain how can it be made thread-safe / show example/ ...
1
vote
1answer
45 views
Receiving data from a network stream in c#
So was my first attempt at some network programming.
I basically have a couple clients built with c#, using System.Net.Sockets TCP connections connecting to a node server backend (first project in ...
2
votes
1answer
80 views
Project Euler #13 efficiency
Okay, so I finally tackled #13 from Project Euler. I'm said to announce it took me almost 2 hours to come up with this solution, after about an hour of thinking on how to do it.
Here's what I did:
...
-1
votes
0answers
41 views
Jquery function not taking value from input[Working but needs improvement] [on hold]
I have the following code for my application.
<div class="btn-group radioButtons amountButtons" data-toggle="buttons-radio">
@if (Model.PresetValues.Count > 0){
...
1
vote
2answers
73 views
List<T> Any vs Count, which one is better for readability?
Resharper thinks I should change this
while (dockPanel.Contents.Count() > 0)
to the following:
while (dockPanel.Contents.Any())
Without thinking twice about it, I switched to the any version ...
0
votes
2answers
40 views
Refactor selective item by highest create date or update date
I have to check for the Highest Date from CostRepository whether it is create date or edit date then i have to get value in that field. edit date can be null. i don't know how to fix the codesmell.
...
-3
votes
0answers
38 views
Test for bulleted list in a string [on hold]
Is there a way for me to determine if there are bulleted lists in a string?
I have a web page which contains a text box. The user can copy/paste or enter a bulleted list in this text box. But I need ...
0
votes
0answers
25 views
Transmitting/Sending big packet safely using TcpClient/Socket
I am writing a TCP based client that need to send and receive data. I have used the Asynchronous Programming Model (APM) provided for Socket class by the .NET Framework.
After being connected to the ...
0
votes
1answer
62 views
Multi threaded application to send large no of emails
I need to build a application which sends a lot of emails. These emails are based on a table. Basic idea is, I grab a bunch of records from database. Create MailMessage (System.Net.Mail) and send it. ...
1
vote
2answers
56 views
Refactor data tranfer object and model
T_PROJECT is the class that will be retrieve data from linq to sql and ProjectOwnerDataFields is the class that will be used to show data in view. in edit mode i have to get value from model and send ...
3
votes
1answer
68 views
Transforming http request into linq query
I wrote something that has probably done thousands of times:
a function that takes a parsed http query as input and return a linq query.
Any input is appreciated.
public IList<Lead> ...
-1
votes
0answers
30 views
Help me understand this sloppy VB [on hold]
OK, I have a bit of old code I am having to modify that was written in VB by a guy who isn't here anymore.
I have a TextBox txtReqID and a TabPanel tp2:
If txtReqID.Text = 0 Then
...
1
vote
1answer
53 views
Review Repository and UnitOfWork implementation
I've done a LOT of reading about creating a Unit Of Work and Repository based implementation for my Entity Framework based application. I have come up with the following - what problems can you find?
...
1
vote
1answer
43 views
Refactor LINQ & XML code
I have some duplicate code using LINQ & XML. I'm sure there is a way to refactor it, but I'm not sure how to go about doing it. Would someone help, please?
var fileInfo = ...
1
vote
1answer
29 views
Refactor LINQ & XML code [duplicate]
I have some duplicate code using LINQ & XML. I'm sure there is a way to refactor it, but I'm not sure how to go about doing it. Would someone help, please?
var fileInfo = ...
2
votes
1answer
71 views
Refactor Linq Expression
Is there any way I can refactor this expression tree?
public static IOrderedQueryable<T_PO> SortedPO(this IQueryable<T_PO> query, ExtjsGridPagingParameter.SortingParameter ...
0
votes
0answers
38 views
enumerating windows to get process via c# & pinvoke approach
as i was trying to have a test and learn about native p/invoke functions i was trying to use only pinvoke and then compare the time it takes to get process info with .net simple
Process myProc = ...
4
votes
2answers
43 views
Filtered wpf textbox
I am tring to make a texbox which filters user input to match specified type, so i can discard some of my validation logic.
For example, if i specify ushort i want my textbox to only accept text ...
-1
votes
1answer
41 views
Log4Net Wrapper with some error potential [closed]
Some time ago, I found the following log4net wrapper here
But I think it is errorprone (in case of threading, could there be deadlocks?)
and the public interface seems to be too wide.
What to do ...
3
votes
1answer
104 views
Please help me follow Repository Pattern properly
I am new to learning Repository Pattern. I am developing a site in MVC 4 ( I m new to it as well). The way I am using Repository pattern as follows:
I created IRepository<T> interface as ...
1
vote
3answers
117 views
Refactoring from if-else-if to Dictionary
I have come across the following piece of code
if (Region.Current == Region.EU)
{
return RegionalPriceLN;
}
else if (Region.Current == Region.NY)
{
return ...
2
votes
1answer
72 views
I've started Tuples to LINQ and I'm not sure if it's an anti pattern
I have
public static class TupleExtensions {
public static IEnumerable<T> SelectMany<T>(this IEnumerable<Tuple<T, T>> te)
{
foreach (var t in te)
{
...
0
votes
0answers
71 views
Can i do this task faster?
I have a problem with this part of code from my program. When i use performance wizard in raport i can see that this exclusive time is 10,96% . How can i improve this code? I ask because when i start ...
4
votes
2answers
124 views
A switch case statement that returns a timespan
I have a switch case statement containing enum values as cases. These enum values are time units. Now I want to generate a timespan by using an enum value and a long value so like this:
2 (long) ...
1
vote
2answers
34 views
TaskFactory.CompleteWhenBoth
I'm trying to construct something which would work a bit like Zip for two tasks, but I'm a bit worried about race conditions in this code.
public static Task<R> ContinueWhenBoth<T1, T2, ...
-3
votes
0answers
27 views
C# - How to pass API Url and fetch the comments from LinkedIn? [closed]
I am trying to get comments from LinkedIn that I have API.
How to call that API and fetch the data from LinkedIn?
Can anyone give an example?
Thanks in advance.
0
votes
1answer
28 views
Is this a good way to track current site being reported on?
I'm trying to find an elegant and secure way to track the currently reported site. I originally just used a cookie but realized this was not very secure. I have since switched to combine the session ...
0
votes
2answers
58 views
Multiple forms for accessing records in database
I have a main form for adding and deleting records and a button that opens a child form that displays records from an access database. Child form will have buttons for moving though the rows like ...
0
votes
2answers
52 views
Is this code thread-safe - Singleton Implementation using Concurrent Dictionary
class Connection
{
private string param1;
private string param2;
private static readonly ConcurrentDictionary<Tuple<string, string>, Connection>
connections = new ...
2
votes
1answer
33 views
How to read fixed-width data fields in .Net
I'm working on a communications layer for a system that reads data from a TCPIP client that is formatted as fixed-width ASCII (yeah, old school). I was quite surprised that there seemed to be no built ...
-1
votes
2answers
62 views
ReferenceEquals vs. == [closed]
I really want to know you opinion about such thing as using ReferenceEquals instead of "==". What do you think? Is that a good idea improve your code readability in that way?
3
votes
2answers
124 views
C# memory game - newbie at C# and bad algorithms galore
Some time ago I had to make a memory game as a college project. I spent around 6hrs coding this since I was also busy juggling exams. I'm not experienced in C# so there are probably a lot of things I ...
1
vote
2answers
49 views
What Data Annotations need to be shared/different between my Model & ViewModel to keep seperation of concerns?
I read this question and answers, about if Display Annotations on model properties violates the separation of concerns between view and model. And my interpretation of their answer was "No, not if ...
2
votes
2answers
73 views
Good implementation of Equals and GetHashCode for base class
Is this a good implementation for Equals and GetHashCode for a base class in C#:
public abstract class Entity<TKey> //TKey = Type of the Key
{
private string FullClassName;
private ...
1
vote
1answer
36 views
The quest for a succint, readable expression of Next in a sequence
I have a need to express something like this:
while(bytesToWrite > 0)
{
// get the NEXT location to write from a Key/Value collection of locations
// read a packet from a file at the ...
1
vote
3answers
85 views
Reduce number of parameters of the same type
I'm looking at a class diagram and it shows a method like this:
SavePrintOptions(bool,bool,bool,bool,bool,bool,bool,bool,bool);
where each of the parameters match up with save options (checkboxes) ...
0
votes
2answers
60 views
Best way to check for specific types
Normally I do this:
if (Animal is Dog)
{
Doc d = (Dog)Animal;
// d. etc..
}
else if (Animal is Cat)
{
Cat c = (Cat)Animal;
// c. ....
}
Is this a good way or are there better ways ...
0
votes
1answer
68 views
Parsing XML in C# .NET [closed]
I am working on a way to parse data using xml.
The file that I am given contains lines that look like this:
George | Washington | Carver
or someone else can send me someting like this
Carver | ...
1
vote
1answer
50 views
Is this routine for determining the epsilon of a Double 100% valid?
This algorithm is intended to determine the epsilon of a given double precision number. As numbers increase in value, their accuracy decreases. This algorithm will return the smallest increment / ...
9
votes
5answers
1k 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 ...
2
votes
1answer
79 views
How can I make this code better
I hate having almost two identical blocks do almost the exact same thing.
I am working with Entity Framework 4.4.0.0
Asp.Net MVC
Right now if the user is a "manager" I want to show them the entire ...
1
vote
0answers
64 views
Is there a better way to convert a MongoDB BsonDocument to XML using C#?
Leaving aside the slightly dubious nature of the request (it's a feature I have to honour, regardless of whether I agree with it, and I'll never be reversing the conversion process), I have devised ...
0
votes
0answers
43 views
Button clicks to add GridViews inside TabContainer, Refactoring
I have a program which is primarily illustrative in example to help me learn refactoring techniques and best practices. This program will take the ActiveTabIndex property of a TabContainer control ...
0
votes
0answers
119 views
Using Barrier to Implement Go's Wait Group
I have implemented a WaitGroup class to simulate WaitGroup in Go lang. Then I've found that I can use Barrier in a different manner, to achieve the same thing. My WaitGroup has some additional ...
2
votes
1answer
49 views
Using ViewState, start-to-end
I'm learning ASP.NET and think I figured out ViewState. Can you tell me if I have it right?
The goal of the ViewState in this page is simply to keep the value in a DropDownList.
So first, let's have ...
1
vote
4answers
133 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
68 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 ...