473,405 Members | 2,282 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,405 software developers and data experts.

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 3407
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.Collections.Generic;
using System.Text;
using System.Threading;

namespace ProduceConsumer
{
class Program
{
static ProducerConsumer _queue;
static void Main(string[] args)
{
_queue = new ProducerConsumer();
new Thread(new ThreadStart(ConsumerJob)).Start();

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

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

public class ProducerConsumer
{
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(listLock);
}
}
}

public int Consume()
{
lock (listLock)
{
while (queue.Count == 0)
{
Monitor.Wait(listLock);
}
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********************@adelphia.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
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...
3
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...
12
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....
2
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...
7
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...
5
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...
4
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 ();...
0
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...
3
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...
4
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
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.