473,395 Members | 1,466 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Threading in Windows Forms

26
Dear All,
Happy to see you all again. I got some useful information from this forum. thats why i am asking. Please give me the valuable information.

I have to run 4 threads parallely in windows form. These Threads to be run on some intervals, so i put in While Loop that is,

Expand|Select|Wrap|Line Numbers
  1. While(IsAvailable) 
  2. {
  3. Thread.Start();
  4. Thread.Sleep(Timespan.FromSeconds(4));
  5. }
The Variable Isavailable set as = true;

All thread are run in same way. If I want to Exit the application i just reset the variable in While Loop IsAvailable = false. and then abort the threads. In above 4 threads 2 thread functions are complicated so thats 2 threads are in running stage the application does not to be closed. After completion of 2 threads the application will be closed. so what i have to do?
And one more question is any other way to wait the thread. if i have put sleep mode its wastes the cpu time. Give your valuable Solution..

Thanks in Advance,
Sekar.
Jul 8 '07 #1
3 1130
Frinavale
9,735 Expert Mod 8TB
Dear All,
Happy to see you all again. I got some useful information from this forum. thats why i am asking. Please give me the valuable information.

I have to run 4 threads parallely in windows form. These Threads to be run on some intervals, so i put in While Loop that is,

Expand|Select|Wrap|Line Numbers
  1. While(IsAvailable) 
  2. {
  3. Thread.Start();
  4. Thread.Sleep(Timespan.FromSeconds(4));
  5. }
The Variable Isavailable set as = true;

All thread are run in same way. If I want to Exit the application i just reset the variable in While Loop IsAvailable = false. and then abort the threads. In above 4 threads 2 thread functions are complicated so thats 2 threads are in running stage the application does not to be closed. After completion of 2 threads the application will be closed. so what i have to do?
And one more question is any other way to wait the thread. if i have put sleep mode its wastes the cpu time. Give your valuable Solution..

Thanks in Advance,
Sekar.
Hi Sekar,

I haven't use threads since school...but I did a bit of research on the problem for you and did find some useful things on MSDN that may help you out.
According to the Thread Members listed (in the last link) it doesn't look like there is a wait function that does what you'd like it to do. There is a SpinWait function that lets you set the number of iterations the thread should wait for though...

Be sure to check out the information on thread pools. I think this will help you out as well.

Cheers!
-Frinny
Jul 9 '07 #2
Plater
7,872 Expert 4TB
If you want your "threads" to only run at a given interval, take a look at the Timer object.

There are a few:
System.Threading.Timer
System.Windows.Forms.Timer
System.Timers.Timer

MSDN has pretty good help on them.
Jul 9 '07 #3
Use this safe abortable thread class publish on MSDN
http://msdn.microsoft.com/msdnmag/is...03/NETMatters/

<email removed>

Dear All,
Happy to see you all again. I got some useful information from this forum. thats why i am asking. Please give me the valuable information.

I have to run 4 threads parallely in windows form. These Threads to be run on some intervals, so i put in While Loop that is,

Expand|Select|Wrap|Line Numbers
  1. While(IsAvailable) 
  2. {
  3. Thread.Start();
  4. Thread.Sleep(Timespan.FromSeconds(4));
  5. }
The Variable Isavailable set as = true;

All thread are run in same way. If I want to Exit the application i just reset the variable in While Loop IsAvailable = false. and then abort the threads. In above 4 threads 2 thread functions are complicated so thats 2 threads are in running stage the application does not to be closed. After completion of 2 threads the application will be closed. so what i have to do?
And one more question is any other way to wait the thread. if i have put sleep mode its wastes the cpu time. Give your valuable Solution..

Thanks in Advance,
Sekar.
Jul 10 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Mahesh Devjibhai Dhola [MVP] | last post by:
We are building Chat like application using Forms and as a result our programming is becoming complicated to display messages received on different threads in the chat window (due to STA...
0
by: Eric Sabine | last post by:
OK, I'm trying to further my understanding of threading. The code below I wrote as kind of a primer to myself and maybe a template that I could use in the future. What I tried to do was pass data...
7
by: Terry Olsen | last post by:
I run this code: Private Sub p_recv(ByVal sender As Object, ByVal e As SerialReceivedEventArgs) Handles p.ReceivedEvent txtRecv.Text += p.ReadExisting End Sub I get this error: ...
3
by: Keith Mills | last post by:
Hello, please find attached a basic outline of what I am attempting to accomplish... basically I want to create a number of THREADS (which I can do fine), but I then need a method for them to be...
0
by: Colmeister | last post by:
I recently read Jason Clark's excellent article on Unhandled Exceptions (http://msdn.microsoft.com/msdnmag/issues/04/06/NET/default.aspx) and have attempted to incorporate the features he talks...
6
by: hzgt9b | last post by:
Using VS 2003, .NET: I developed a windows application that performs several actions based on an input file. The application displays a progress bar as each action executes. Based on new...
14
by: Simon Verona | last post by:
I think I'm doing this wrong : I have a class with a public shared method such as follows: public shared sub myFunction dim frm as new myFrm dim t as new Threading.Thread(Addressof ...
7
by: Mike P | last post by:
I am trying to write my first program using threading..basically I am moving messages from an Outlook inbox and want to show the user where the process is up to without having to wait until it has...
19
by: frankiespark | last post by:
Hello all, I was perusing the internet for information on threading when I came across this group. Since there seems to be a lot of good ideas and useful info I thought I'd pose a question. ...
9
by: tshad | last post by:
I have a Windows App that is doing some work and then writing a "Now Processing..." line to the status line of the window as well as the Textbox on the form. But the problem is that the work is...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.