As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I want to get a good grasp of multi-threading in C#. I've read some articles like Joseph Albahari's tutorials that explain the concepts, but as you know, no matter how much you read, most of it becomes rubbish if you don't practice. I need something that has instructive and pragmatic code examples related to real life practices, not some examples that print some lines. Do you have any suggestions?
guys guys I think I found a good site: planet-source-code.com. Searching in .Net codes with "thread" keyword seems to return some good examples, like
multi threaded folder synchronization
multi threaded TCP server
background file downloader
async. socket
P2P file sharing
simple POP3 console mail checker and lots of others!
yay!
Some kind of random number-crunching is a good test for this. I taught myself threading by writing a prime number finder, then breaking my "search" numbers into blocks and using a thread to work through each one.
This let me set some variables on block size, number of threads to use, wait time between firing threads etc. to test how each of these affects performance.
If you're doing any winforms or wpf development, you'll quickly run across issues when you try to do "stuff" in the UI thread.
Let's say that you need to read and parse the contents of a large (2GB) XML file. If the work were performed in the UI thread, the interface would hang until the work had been completed. Conversely, if you were to do the work correctly in a worker thread, then you could keep the UI responsive via messaging and let the user know what you're currently doing (status bar (ugh,) or display in text what you're doing "Reading XML.", etc.)
A good simple example would be to make a sample application and have it fire off a BackgroundWorker to handle some arbitrary work in the background (it could even be Thread.Sleep(10000), or something trivial like that.)
I'd say this is one of the many good starting points out there on the subject.
http://msdn.microsoft.com/en-us/library/cc221403%28VS.95%29.aspx
This site has a few sample applications that I think would be decent practice applications to implement. However, it seems like the links to the source code are broken. Nonetheless, I believe the applications presented represent very practical examples. A few include:
Desktop Search
Download Manager
FTP Client
File Compression
Multiple RSS Feeds
Related
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
I read this question Asynchronous vs Multithreading- is there a difference and search in Google about differences.
What is the benefit to use Asynchronous instead of Multithreading?
and when use Asynchronous instead of Multithreading?
If your task can be done using asynchronous programming, the it is better to do it that way instead of going for multi-threaded programming. for 3 reasons:-
1: Perfomance
In multi-threading, the CPU or w/e has to keep switching between threads. So, even if your thread is doing nothing and just sitting there (or more likely, doing a comparison to see if a condition is true so it can get one with doing with w/e it was created to do), the CPU still switches threads and the process takes some time. I don't think that would be very bad, but your performance surely takes a hit.
2: Simplicity & Brevity
Also, maybe it's just me, but asynchronous programming just seems more natural to me. And before you ask, no, I'm not a fan of JS but still. Not only that, but you run into problems with shared variables and thread-safeness and others — all of which can be side-stepped by using asynchronous programming and callbacks.
3: Annoying implementations of threads
In Python there's this really horrible thing called a GIL (Global Interpreter Lock). Basically, Python doesn't let you actually run concurrent threads. Also, if you're thinking about running a threaded program on a multi-core CPU, forget it.
There might be caveats in C# too, I don't know. These are just my 2 cents...
All that said, asynchronous and multi-threading are really not that comparable. While multi-threading may be used (inefficiently) to implement asynchronousity, it is a way to get concurrency and acynhrounousity is a programming style, like OOP (Object Oriented Programming).
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I'm implementing a SOAP Webservice for sending thousands of emails and storing thousands of XML response records in a local database. (c#.net, visual studio 2012)
I would like to make my service consumer as fast and lightweight as possible.
I need to know some of the considerations. I always have a feeling that my code should run faster than it is.
E.g.
I've read that using datasets increase overhead. So should I use lists of objects instead?
Does using ORM introduce slowness into my code?
Is a console application faster than a winform? Because the user needs no GUI to deal with. There are simply some parameters sent to the app that invoke some methods.
What are the most efficient ways to deal with a SOAP Web Service?
Make it work, then worry about making it fast. If you try to guess where the bottle necks will be, you will probably guess wrong. The best way to optimize something is to measure real code before and after.
Datasets and ORM and win form apps, and console apps can all run plenty fast. Use the technologies that suit you, then tune the speed if you actually need it.
Finally if you do have a performance problem, changing your choice of algorithms to better suit your problem will likely yield much greater performance impact than changing any of the technologies you mentioned.
Considering my personal experience with soap, in this scenario I would say your main concern should be on how you retrieve this information from your database (procedures, views, triggers, indexes and etc).
The difference between console, winform and webapp isn't that relevant.
After the app is done you should make a huge stress test on it to be able to see where lies your performance problem, if it exists.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 11 years ago.
I was wondering if there are best well-known methods, architectures, 3rd party libraries, etc to help developers program UI?
I am thinking about something which would help in the following areas:
When looking into the code written by someone else,
I would like to know instantly, what UI serves, what are the states of the UI,
From which does the state depend on?
Something which could clearly separate logic for each state
State for me would be the state of all components when:
user run winform
user makes a decision and executes some action, The result of his action
is another state of UI Form
user leaves the form
etc.
For me as a developer, programming in mvc, which is a good, because allow to seperate logic(view, manipulating and data access) it is still confusing when I see events doing something, which to be honest I have to re-think in which situation that may occur, what and when it is doing...
Do you know what I mean?
Any suggestions greatly appreciated..
In WinForms this is hard, since the GUI and code behind is very tightly coupled.
I would recommend using WPF instead, and a MVVM (Model-View-ViewModel) framework as Caliburn.Micro to better separate the GUI from the logic. It's a much better model for development than WinForms ever was.
I was wondering if there are best well-known methods, architectures, 3rd party libraries, etc to
help developers program UI?
Why do you wonder? You have a 100% chance that, because there are more than one of them, the answer will never be no.
When looking into the code written by someone else, I would like to know instantly, what UI
serves, what are the states of the UI, From which does the state depend on?
Delusional. This will never happen even when standardizing the code base unless the cases are trivial.
At the end, regardless of how many patterns you follow, a complex UI is a complex UI and you won't get this down to the level of "how many types of burgers are at McDonald's". If you don't want to think, then work at McDonald's.
Patterns may help, but forms vary widely and, outside of simple showcase patterns, etc., they won't get you "instant, don't think" access to other people's code.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 9 years ago.
Last week I interviewed for a position at a TripleA MMORPG game company here in NE. I didn't get the job but one of the areas that came up during the interview was the about the scalability of the code that you write and how it should be considered early on in the design of your architecture and classes.
Sadly to say I've never thought very much about the scalability of the .NET code that I've written (I work with single user desktop and mobile applications and our major concerns are usually with device memory and rates of data transmission). I'm interested in learning more about writing code that scales up well so it can handle a wide range of remote users in a client server environment, specifically MMORPGs.
Are there any books, web sites, best practices, etc. that could get me started researching this topic?
Here are some places to start:
http://highscalability.com/blog/2010/2/8/how-farmville-scales-to-harvest-75-million-players-a-month.html
http://www.cs.cornell.edu/people/~wmwhite/papers/2009-ICDE-Virtual-Worlds.pdf
In particular, http://highscalability.com is full or articles about huge websites that scale and how they do it (Digg, flickr, facebook, YouTube, ...)
Just one point I'd like to highlight here. Just cache your reads. Work out a proper caching policy where you determine which objects can be cached and for what periods. Having a distributed caching farm will take load off your DB servers, which will greatly benefit performance.
Even just caching some pieces of data for a few seconds - in a very high load multi-user scenario - will provide you with substantial benefit.
If you are looking for physical validation, what I usually find that helps is doing some prototyping. This gives you a good idea usually of any unforeseen problems that might be in your design and just how easy it is to add onto it. I would try to apply any design patterns possible to allow future scalability. Elements of Reusable Object-Oriented Software is a great reference for that. Here are some good examples that show before and after code using design patterns. This can help you visualize how design patterns could make your code more scalable as well. Here is an SO post about specific design patterns for software scalability.
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
What would you suggest as a road map for becoming very proficient in writing multithreaded applications - beyond "tinkering"?
I am a C# developer - would branching off into some other languages help this endeavor?
Does the parallel addition to .NET 4.0 hide things that you should know in order to make it easier?
Read Joe Duffy's "Concurrent Programming on Windows". Joe is an amazing expert.
Investigate different approaches to concurrency on different platforms; look at Erlang, Scala etc
Likewise read Java concurrency books, which will have some subtly different details, but often tackle the same core issues and have some useful patterns. "Java Concurrency in Practice" is often recommended.
Look at the various options on .NET, including the Coordination and Concurrency Runtime and F# asynchronous computations
Definitely learn Parallel Extensions - it'll help a lot, and from what I've seen, a lot of very careful design work has gone into it. (It's changing somewhat for 4.0b2 though, so you may want to defer this for now.)
Theres a really good PDF about threading in .NET here the MSDN documentation for the Thread class as well as the threading primitives (Mutex, WaitHandle, ReaderWriterLockSlim et al) is also good reading.
The key things to understand are:
When to use a thread
When not to use threads
How to manage sharing state between threads.
I could go on to explain these here, but I feel the threading PDF linked to above does a far better job than I could in that respect, the key point is that threads are a powerful tool and understanding when and how to use them will make you more proficient in their use than simply reading MSDN, although strategies for using threads effectively are covered there also.