HI
Ok, i understanded what is multithread but can anyone show an example of a simple simple simple program using multi thread or point to a good tutorial
Thanks..
HI
Ok, i understanded what is multithread but can anyone show an example of a simple simple simple program using multi thread or point to a good tutorial
Thanks..
simple multi thread in c#
Ben628751
"Give Your .NET-based Application a Fast and Responsive UI with Multiple Threads"
RandyHayes
Hi,
this is "Hello, World" example using C# in a console application, if you use another type of application the concept still as it is. you only need to define what you need:
using System;
using System.Threading;
public class Test {
static void Main() {
ThreadStart job = new ThreadStart(ThreadJob);
Thread thread = new Thread(job);
thread.Start();
for (int i=0; i < 5; i++) {
Console.WriteLine ("Main thread: {0}", i);
Thread.Sleep(1000);
}
}
static void ThreadJob() {
for (int i=0; i < 10; i++) {
Console.WriteLine ("Other thread: {0}", i);
Thread.Sleep(500);
}
}
}
ilango2006
and btw i dont think that multi thread are that "science rocket" since other people learn it when they wore just like me or maybe they`ve been born already knowing multi thread
Ok -- more specific information about what i want to do
i want to have a label1 that will infinitly change,
and still let the user to move the windows push buttons and others..
Is that hard to do it
Umair.it
My comment about 'rocket science' wasn't aimed at you. It really is challenging to get multithreading right. And by 'right' I mean creating a multi-threaded application that is not prone to random freezes or slow-down to due to incorrect or inefficient locking. Believe me when I say that no one is born knowing multi-threading. In fact, most multi-threading experts make mistakes when writing multi-threaded applications.
With respect to what you're trying to do, what is the trigger to changing Label1 One of the main issues with multi-threading in a Windows application is that all access to the properties on the controls must be done through the main UI thread. So let's say that you followed Saleh's model and spawned a background thread that would do something and change Label1.Text. This violates the 'access properties on Main UI' rule and leaves you open to random problems. So you need to use the Invoke method on the control or form to call a method to update the Text property.
lee_connell
You might want to be a little more specific with your question. What are you trying to multithread Are you doing this within a Windows Forms application A web application Each of these scenarios has different factors.
And, just to add feul to the fire, I'm of the opinion that multithreading is too complicated for most developers to have to deal with. You know that to non-developers what programmers do is rocket science Well to normal developers, multithreading is rocket science. It's way to easy to creation situations where sporadic problems/bugs happen.
Just my two cents.