|
It's not really clear to me yet, sorry..
|
|
|
|
|
Seems like what you need is a queue object: the SMS-handling thread(s) after processing received messages add their AT command to the queue; the 'AT handler' thread waits on the queue being not-empty and processes the command at the front of the queue.
So - one thread per modem, and one queueing object to coordinate them. Plus the foreground thread that your UI operates on.
Just remember to lock the queue object before any operations that touch it since it is being touched by multiple threads.
|
|
|
|
|
Thanks for the reply Chris.
Chris Trelawny-Ross wrote: So - one thread per modem
Yes, i agree with you. That's the concept on my mind on my "large code".
It will be array of threads.
|
|
|
|
|
I dont have a whole lot of experience with threading, but wouldn't it make sense to have your for loop run on its own thread so when you call Join() it locks the current thread (the new thread your for loop is running on)?
So when your button is clicked launch a new thread that runs your for loop.
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
Thank you Adam for the reply.
Sorry Adam, i didn't quite understand your point of view.
Maybe you can provide some "scratch code"?
|
|
|
|
|
As per usual Luc is correct.
But to accomplish what i was saying try something like this.
* note: this is just written into the browser so im sure it wont compile *
private void button1_Click(object sender, EventArgs e)
{
.. disable button
Thread myThread = new Thread(new ThreadStart(Run))
myThread.Start();
}
private void Run(){
for (int j = 0; j < 3; j++)
{
i = j;
myCurThread = new Thread(new ThreadStart(myThread));
myCurThread.Start();
myCurThread.Join();
}
}
private void myThread()
{
....
}
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
Yes, i think this is what you mean in the first reply.
Yes, it's a good logic, Adam. Can i say this is thread inside a thread?
And yes, i try it and it worked. I will try it on "large code".
Thanks Man!.
|
|
|
|
|
Yes, this is a thread inside a thread ... inside a thread.
Really when your application launches a thread is created, your main thread (Thread Count = 1), then when the user clicks the button you launch another thread (Thread Count = 2) then your 2nd thread creates another thread (Thread Count = 3).
This probably isnt the best method to accomplish this, see Luc's post, but it will get the job done.
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
The count there is no use on "large code". I just want to examine that the threads is run on order or not.
Thanks for the suggestion about luc post.
|
|
|
|
|
Use a BackgroundWorker started when the button is clicked. The bgw can then either process each ComPort in sequence (as someone else said, if they are running sequentially, why bother with separate threads?), or the bgw can fire off its own child threads and wait for them to finish, as above. Because the bgw is doing the work, your form remains responsive while the long-running process is under way even if the bgw thread itself is paused or busy. Of course, you then have to decide what happens if someone tries to click the button again while the background thread is already running.
|
|
|
|
|
Thank you David for the reply.
Yes, i will keep it on my mind about BackgroundWorker. Until now, i had not use BackgroundWorker at my "large code" but suppose if i'm having trouble with the UI, i will try the BackgroundWorker.
|
|
|
|
|
if you want a number of operations to be executed in sequence, but without freezing your GUI, you need exactly one extra thread (Thread, ThreadPool thread, BackgroundWorker) that executes those operations one after the other.
And your GUI thread should never wait on them (nor on anything else) and not call Thread.Join(); instead you should keep your GUI active, however also disable the features you want disabled for as long as the other thread is working for you.
|
|
|
|
|
Thank you for the reply Luc.
Ok, i see there's 3 key point here to solve the problem :
1. Thread
2. ThreadPool
3. BackgroundWorker
I will investigate it further.
|
|
|
|
|
Endien wrote: 3 key point here to solve the problem
No, the key points are to keep the GUI/main thread free, never to block it, and to hire as many other team players as you need, no more, no less.
The exact type of your additional team player is of minor importance. BackgroundWorker is slightly harder to set up, but offers advantages for reporting progress, completion, and exceptions.
|
|
|
|
|
Hello...
How can I get the Length of a column of an sql table from my C# code....
In my application I am using databound controls. I want to know the length of the field in UI.
any help would be appreciated...
Thanks
Sebastian
|
|
|
|
|
|
See this[^] recent thread.
|
|
|
|
|
|
When I install the Code Project search toolbar, its background color is the default color for the Windows os it's running in -- that is, gray for XP, blue for Vista. I have made my own toolbar with a toolstrip in a Band Object, and everything works fine, except that I cannot get the background color to be the default. I can make a bitmap for the background, but if someone changes their theme my toolbar will then be the wrong color.
Susan
|
|
|
|
|
System.Drawing.SystemColors.WindowFrame Maybe ?
SystemColors Members[^]
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
I tried WindowFrame, and a whole bunch of others, none of which look like the color of the toolbars in Vista, which is my development operating system.
|
|
|
|
|
Well i'm out of ideas ..... Is it just the transparency of the toolbar that is making the colours differant? or is the colour just way off?
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
The color is way off -- but I'm not sure I understand what you mean by the transparency of the toolbar.
|
|
|
|
|
Well on Vista & 7 the toolbars have a slight transparency to them (Areo) which could mess with the colour.
Just a thought, have you tried enabling themes. I can't remeber where but I recal that being an issue with something I was working on awhile ago. I can't remember the object or actual property but I do remeber it was a problem. Might not help ... but you never know.
If at first you don't succeed ... post it on The Code Project and Pray.
|
|
|
|
|
Thanks for the tip. I did some research and found the "Application.EnableVisualStyles" method. I called it from the constructor of my toolbar, and after I called it I displayed "Application.RenderWithVisualStyles", the value of which was true. However, my toolbar and its controls are still gray. Do you know how I should be setting the background color to work with EnableVisualStyles?
Susan
|
|
|
|