473,804 Members | 2,008 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

tread complete notification

How would I signal the main app when a thread has completed a task.

The thread must remain actice. Every time it reads a given number of bytes
it must let the main app know, then wait until more data shows up. The
number of bytes it reads varies.

Thanks,
Bill
Nov 17 '05 #1
3 3419
Sounds like a good use for events.

"bill" wrote:
How would I signal the main app when a thread has completed a task.

The thread must remain actice. Every time it reads a given number of bytes
it must let the main app know, then wait until more data shows up. The
number of bytes it reads varies.

Thanks,
Bill

Nov 17 '05 #2
Bill,

This is a very classic producer - consumer issue. Multi-threading
programming 101.

I give you an example here, I get this from some body else's website.
Here a monitor is used. I believe there are other approaches too..
using System;
using System.Collecti ons.Generic;
using System.Text;
using System.Threadin g;

namespace ProduceConsumer
{
class Program
{
static ProducerConsume r _queue;
static void Main(string[] args)
{
_queue = new ProducerConsume r();
new Thread(new ThreadStart(Con sumerJob)).Star t();

Random rng = new Random(0);
for (int i = 0; i < 10; i++)
{
Console.WriteLi ne ("Producing {0}", i);
_queue.Produce( i);
Thread.Sleep(10 00);
}
}

static void ConsumerJob()
{
Random rng = new Random(1);
for (int i = 0; i < 10; i++)
{
int iConsume = _queue.Consume( );
Console.WriteLi ne("\t\t\tConsu ming {0}", iConsume);
Thread.Sleep(rn g.Next(1000));
}
}
}

public class ProducerConsume r
{
readonly object listLock = new object();
Queue<int> queue = new Queue<int>();

public void Produce(int i)
{
lock (listLock)
{
queue.Enqueue(i );
if (queue.Count == 1)
{
Monitor.Pulse(l istLock);
}
}
}

public int Consume()
{
lock (listLock)
{
while (queue.Count == 0)
{
Monitor.Wait(li stLock);
}
return queue.Dequeue() ;
}
}
}
}
bill wrote:
How would I signal the main app when a thread has completed a task.

The thread must remain actice. Every time it reads a given number of bytes
it must let the main app know, then wait until more data shows up. The
number of bytes it reads varies.

Thanks,
Bill

Nov 17 '05 #3
Hi,

You can use Control.Invoke to force the execution of a method in the UI
thread, this can be used for a progressBar , etc
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"bill" <wj****@hotmail .com> wrote in message
news:lJ******** ************@ad elphia.com...
How would I signal the main app when a thread has completed a task.

The thread must remain actice. Every time it reads a given number of bytes
it must let the main app know, then wait until more data shows up. The
number of bytes it reads varies.

Thanks,
Bill

Nov 17 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
8376
by: grutta | last post by:
I am writing a windows service that will recieve notification when a USB Device is insterted into the machine. I have used the RegisterDeviceNotification and the RegisterServiceCtrlHandlerEx with a handler. The handler portion seems to fail indicating that my parameters are invalid. I am getting an error code 126 when i try to register the handler and 28 when i register for event notification. Any ideas as to what the deal is? I am...
3
1727
by: Marty | last post by:
Hi, I have two questions, First, does anybody know how to quantify the relation between the number of threads, the amount of RAM and the CPU power? Secondly, does a System.Threading.Timer is lighter in used ressources than using a thread ? why? Does it start/stop faster than a thread ? why?
12
15927
by: Anders Eriksson | last post by:
Hello! I'm trying to create a program that will watch a directory and when a file is created print that file. I have used FileSystemWatcher for watching the directory and I get an created event. The problem is that I don't know when the file is complete when using Explorer copy or move. I have tried to use FileIOPermission but I always get that the file is
2
3507
by: SB | last post by:
Can someone please tell me Microsoft .NET's position on this WS-Notification specification that includes the pub/sub model? Is there something in the pipeline or already available as part of the .NET or WSE? -- Kind regards, SB
7
2177
by: GeorgeAtkins | last post by:
I want to create a web-based form or page that consists of a series of formatted questions and answers. The form will resemble an existing paper form. When the form is filled in, I want the user to submit the form via e-mail and have the complete form with answers sent, not just the data. That is, the recipient should be able to open the attachment and see (and print) the complete, formatted form. It seems to me that solutions simply...
5
2304
by: Ryan Liu | last post by:
Hi, I read Microsoft SDK, ms-help://MS.NETFrameworkSDKv1.1/cpguidenf/html/cpovrasynchronousprogramming overview.htm there are 4 ways to call EndInvoke: The code in this topic demonstrates four common ways to use BeginInvoke and EndInvoke to make asynchronous calls. After calling BeginInvoke you can:
4
2520
by: cyrous xiao | last post by:
I hvae three thread and a thread that is used to show a winform. The code: Thread ThreadDialog= new Thread (new ThreadStart (ShowDialog)); //Show a winform Dialog ThreadDialog.Start (); Thread Thread1= new Thread (new ThreadStart (Thread1Func)); Thread1.Start (); Thread Thread2= new Thread (new ThreadStart (Thread2Func));
0
1632
by: vsrprasad16 | last post by:
Hi All, I am implementing a notification form similar to outlook email notification. my application call this notification form from a dll. this dll includes a form class and this dll has some object value to display the contents on form. i am filling the form with the object before "form.show." form has some timer to implement hide and fading. my problem is when ever form is showing, the focus goes to form from current application(any)...
3
4027
by: TS | last post by:
I am using IE 7. I have a website running on my local machine (localhost) and auto complete doesnt work for any of the textboxes, but going to web sites on the internet does support this so i know the browser has this config turned on. any ideas why it doesnt work on my local web application (.net 2)? thanks
4
3320
markmcgookin
by: markmcgookin | last post by:
Has anyone used the notification class from Windows CE forms? using the following code using Microsoft.WindowsCE.Forms; ... Notification note = new Notification()
0
9711
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9593
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10595
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10343
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9169
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5668
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4306
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3831
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3001
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.