if I start a thread
mythread.start
and then I click a button that has a do loop with no doevents in the
loop,
do
loop until myval=true
the first thread never finishes as the do loop hogs resources.
question: how can I make mythread continue despite the do loop problem?
and can it be done without using doevents?
thanks 9 1116
Hi,
What does myThread do ? And what's the problem with using DoEvents ?
In my view, one of the purposes of having a multi-threaded application
is to prevent long processes from blocking out the main or UI thread,
and keep the application responsive.
So, why not move your do...loop to another thread, instead of running
it on the main UI thread ?
Regards,
Cerebrus.
it's kind of like this...
I have a routine building a csv file. I'm doing this ahead of the user
needing it. A bit of forward planning. I start creating the csv file
when the user pops up a window. they then spend some time entering
data, and click OK.
now if the thread that was creating the csv file has finished, the OK
button works and does its stuff. if the OK button is pressed and the
thread building the csv file is still running, I need to wait until it
is does. So at the moment I just loop until it is. If I put a doevents
in the loop the user can keep clicking everything on the form, and
things get messy. Without the doevents, the background thread never
completes.
any ideas?
When you start the thread that is creating the csv file, save the thread
variable. Then use it's join method
dim ThreadToCreateC SV as new thread
ThreadToCreateC SV.start()
In you OK handler, use the following statement
ThreadToCreateC SV.Join
Mike Ober
"Tim" <Ci************ @gmail.com> wrote in message
news:11******** **************@ i39g2000cwa.goo glegroups.com.. . it's kind of like this...
I have a routine building a csv file. I'm doing this ahead of the user needing it. A bit of forward planning. I start creating the csv file when the user pops up a window. they then spend some time entering data, and click OK.
now if the thread that was creating the csv file has finished, the OK button works and does its stuff. if the OK button is pressed and the thread building the csv file is still running, I need to wait until it is does. So at the moment I just loop until it is. If I put a doevents in the loop the user can keep clicking everything on the form, and things get messy. Without the doevents, the background thread never completes.
any ideas?
thread.join, excellent thank you.
I'll go and read up about it.
If you want to expand a little more while I am away reading that would
be very helpful.
Cheers
Tim wrote: I have a routine building a csv file. I'm doing this ahead of the user needing it. A bit of forward planning. I start creating the csv file when the user pops up a window. they then spend some time entering data, and click OK.
now if the thread that was creating the csv file has finished, the OK button works and does its stuff. if the OK button is pressed and the thread building the csv file is still running, I need to wait until it is does. So at the moment I just loop until it is. If I put a doevents in the loop the user can keep clicking everything on the form, and things get messy. Without the doevents, the background thread never completes.
Does it really take that long to create the csv file? If you're building it
using strings then using a StringBuilder may be a much better solution. If
you're writing the file one line at a time then consider building it in a
StringBuilder and writing that to a file in one go.
Andrew
Andrew, Does it really take that long to create the csv file? If you're building it using strings then using a StringBuilder may be a much better solution. If you're writing the file one line at a time then consider building it in a StringBuilder and writing that to a file in one go.
Almost impossible that the user is able to click on a button during that
time. Or the OP should get the data from something as internet on a 19.2
line and build the CSV direct without getting first the data..
Using a thread for this will consume probably the most time.
Just my thought,
Cor
Tim,
Thread.Join will block the thread from which is called. In your case
it would be the UI thread. That will effectively stop the message loop
and prevent the user from interacting with the form.
A better approach is to have the thread raise an event notifying your
form that its work is complete. Your form would subscribe to this
event before starting the thread. Just remember to use Control.Invoke
to marshal the execution of code onto the UI thread before accessing
any controls on your form.
Brian
Tim wrote: thread.join, excellent thank you. I'll go and read up about it.
If you want to expand a little more while I am away reading that would be very helpful.
Cheers
thank you guys for all your input.
the csv building is actually very quick. the content for the csv file
however comes from a webservice, and might well be several thousand
rows of data (this is the exception. typically only a few rows will be
required).
I tried the .join thing and it worked. I'm also happy that is locks the
form while it waits (that is exactly the functionality I was after)
Brian wrote this
"A better approach is to have the thread raise an event notifying your
form that its work is complete. Your form would subscribe to this
event before starting the thread. Just remember to use Control.Invoke
to marshal the execution of code onto the UI thread before accessing
any controls on your form."
I don't understand it, but it sounds like something I should know about
so I'll investigate further.
Add this inside your do loop.
Threading.Threa d.Sleep(100) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: adeger |
last post by:
Having trouble with my first forays into threads. Basically, the
threads don't seem to be working in parallel (or you might say are
blocking). I've boiled my problems to the following short code block
and ensuing output. Seems like the output should be all interleaved
and of course it's not. Running Python 2.2 from ActiveState on
Windows XP (also doesn't work on Windows 2000).
Thanks in advance!
adeger
|
by: jrlen balane |
last post by:
basically what the code does is transmit data to a hardware and then
receive data that the hardware will transmit.
import serial
import string
import time
from struct import *
ser = serial.Serial()
|
by: Jeff Yang |
last post by:
These days,I have read the artile "Safe, Simple Multithreading in Windows
Forms, Part 1" on MSDN,and I also runed the example of it.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnforms/html/winforms06112002.asp
The question is In function void ShowProgress(string pi, int totalDigits,
int digitsSoFar);
if I use Invoke(showProgress, new object { pi, totalDigits,
digitsSoFar});the UI performs better(it responses to my...
|
by: Peter |
last post by:
Hello
Thanks for reviewing my question. I would like to know how can I programmatically select a node
Thanks in Advanc
Peter
|
by: Elliot Rodriguez |
last post by:
Hi:
I am writing a WinForm app that contains a DataGrid control and a StatusBar
control. My goal is to update the status bar using events from a separate
class, as well as some other simple things.
The method I am writing queries a large dataset. As part of my feedback to
the user, I am updating the status bar when the connection is made and the
dataset is actually retrieved. The dataset retrieval method I have placed on
a separate...
| |
by: Brian Henry |
last post by:
Hello,
I was tring to learn socket's (being i never used them before) and have a
simple question. I want to create a listner that will get any data recieved
and print it out. I've been able to get it to recieve only one line of data,
but the next one i send to it wont be printed like the 1st one. I had a
listner running in a thread, does anyone have a simple listner code example
that would show how to have a tcplistner thread running...
|
by: Claudio Grondi |
last post by:
In the process of learning about some deeper details of Python I am
curious if it is possible to write a 'prefix' code assigning to a and b
something special, so, that Python gets trapped in an endless loop in a
line with:
if a==b: print 'OK'
I mean, it would be of much help to me on my way to understanding Python
to know how such prefix code leading to an endless loop can look like
and if it is eventually not possible to write such...
|
by: Ryan Pedersen |
last post by:
I have a small program that executes a single very long running
background thread today.
The scope of all variables in the method that is running in this
thread today are all local to the method. The method doesn't do
anything outside of its local scope.
My question... can I start up a 2nd (3rd, and 4th and so on) thread
running the same method? Is that safe?
|
by: nw |
last post by:
Hi,
I previously asked for suggestions on teaching testing in C++. Based
on some of the replies I received I decided that best way to proceed
would be to teach the students how they might write their own unit
test framework, and then in a lab session see if I can get them to
write their own. To give them an example I've created the following
UTF class (with a simple test program following). I would welcome and
suggestions on how anybody...
|
by: Chris M. Thomasson |
last post by:
I use the following technique in all of my C++ projects; here is the example
code with error checking omitted for brevity:
_________________________________________________________________
/* Simple Thread Object
______________________________________________________________*/
#include <pthread.h>
extern "C" void* thread_entry(void*);
|
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,...
| |
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...
|
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...
|
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...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |