473,750 Members | 2,186 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How repaint a from when a main thread is blocked ?

Hi

My main thread is waiting for data from database ( opened Sqlconnection etc)
and my Main Form is also blocked. I have a ProgressBar on Status Bar which
show to a user how percent data is loaded. I use ThreadTimer and Thread but
I can't do anything because when a thread (or ThreadTimer) go to the line
ProgressBar.Pef romStep() then it stop on that line. I think it's work like
that because the Main Thread (and main Form) is sleeping.
Can you give me any ideas how I can do that ? Maybe this problem disapear
when I load data in other thread and my Main Thread is free but it doesn't a
good idea.
Thank's all for any help.

Thank's Boniek
Nov 16 '05 #1
3 3582
On Thu, 17 Jun 2004 16:51:01 +0200, "Boniek" <mo****@poczta. onet.pl>
wrote:
Maybe this problem disapear
when I load data in other thread and my Main Thread is free but it doesn't a
good idea.


It's the only possible solution, though. The main GUI thread paints
all your windows; if that thread is blocked you don't get window
updates, and that is that. You must place the blocking operation in a
separate worker thread. Be sure to check the various MSDN articles on
multithreading with Windows Forms for how to do this.
--
http://www.kynosarges.de
Nov 16 '05 #2
Hi,

I really don't think you have an option. If you want your main thread
to be free, well... it has to be free! If it's blocked by a call to
fetch data from the database, then it simply isn't going to do
anything until that call returns. The timer calls are returning fine
because they run on worker threads. But as long as the form thread is
blocked, you won't see the updates to the progress bar simply because
the form can't paint itself.

Ideally, you should offload such calls to another thread and keep your
UI thread unblocked at all times. Just remember that if you do choose
to use another thread, then you must use Form.Invoke to update the
progress bar.


"Boniek" <mo****@poczta. onet.pl> wrote in message news:<40******@ news.home.net.p l>...
Hi

My main thread is waiting for data from database ( opened Sqlconnection etc)
and my Main Form is also blocked. I have a ProgressBar on Status Bar which
show to a user how percent data is loaded. I use ThreadTimer and Thread but
I can't do anything because when a thread (or ThreadTimer) go to the line
ProgressBar.Pef romStep() then it stop on that line. I think it's work like
that because the Main Thread (and main Form) is sleeping.
Can you give me any ideas how I can do that ? Maybe this problem disapear
when I load data in other thread and my Main Thread is free but it doesn't a
good idea.
Thank's all for any help.

Thank's Boniek

Nov 16 '05 #3
A better strategy is to create a new thread, connect to the database on that
thread, and then have your main thread use
Thread.Join calls to wait and increment your progress bar during the
connection

"Boniek" <mo****@poczta. onet.pl> wrote in message
news:40******@n ews.home.net.pl ...
Hi

My main thread is waiting for data from database ( opened Sqlconnection etc) and my Main Form is also blocked. I have a ProgressBar on Status Bar which
show to a user how percent data is loaded. I use ThreadTimer and Thread but I can't do anything because when a thread (or ThreadTimer) go to the line
ProgressBar.Pef romStep() then it stop on that line. I think it's work like
that because the Main Thread (and main Form) is sleeping.
Can you give me any ideas how I can do that ? Maybe this problem disapear
when I load data in other thread and my Main Thread is free but it doesn't a good idea.
Thank's all for any help.

Thank's Boniek

Nov 16 '05 #4

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

Similar topics

4
4938
by: Dr. J | last post by:
How to terminate a blocked thread? In my form's "load" I launch a TCP listening thread that stays in an infinite loop waiting for incoming TCP packets. In this form's "closing" I try to terminate this thread by calling the "Abort" funcion. But the thread does not terminate and after the form is closed this thread keeps running at blocked state. Basically the application keeps running because this thread does not terminate while...
10
1991
by: Nak | last post by:
Hi there, After recently coming across issues with implementing a UDP server for interprocess communication; involving file transfer, I have decided to go onto TCP. Now I *have* created a TCP server in the past for VB.NET but had troubles when it comes to disconnecting all clients and cleaning up remaining references. The problems arrise when using the IAsyncResult for receiving data, once started a method is needed to successfully...
11
1217
by: TrtnJohn | last post by:
I have a class that writes data to the serial port and has a separate thread to read data from the same port. Typically the main thread writes requests to the serial port and then returns to the caller. The read thread waits for a response while the application continues running. When a response is received, I want to fire an event. But, I don't want the read thread to raise the event because the event could spawn a whole set of new...
5
3257
by: Paul Hasell | last post by:
Hi, I'm trying to invoke a web method asynchronously but just can't seem to get it to tell me when it has finished! Below is the code I am (currently) using: private void btnUpload_Click(object sender, System.EventArgs e) { try { SOPWebService.Client uploader = new
4
7574
by: DaveR | last post by:
I have a background thread to accept and process TCP/IP connections. When the application shuts down I want to gracefully terminate it. The thread will block in NetworkStream.Read() waiting for data. I expected that shutting down the TcpListener would unblock the Read() and cause an exception, or return 0 bytes. But it does not work. Relevant parts of the code are shown below. If a client connects, the stream blocks in its Read()...
5
6451
by: many_years_after | last post by:
Hi, pythoners: There is a problem I couldn't dispose. I start a thread in the my program. The thread will do something before executing time.sleep(). When the user give a signal to the main thread (such as click the 'end' button or close the window), the thread should end it's running. But how to end the threading when it's sleeping? I set an flag to the thread, but it doesn't work. I also thought to put 'time.sleep()' to the main...
2
2184
by: giddy | last post by:
hi , I'm in a slight dilemma. I have an updater program that checks for pending updates and downloads them if the users chooses to. Since i dont need a windows form to check if there is an update , I dont use a form unless i have two. This , creates either one of two problems. When i'm downloading asynchonously , the main thread exits!
4
2387
by: RSH | last post by:
Hi, I have an Asynchronus process that is reporting back to the UI at regular intervals. I read several posts on how to use delegates to make this happen. But for some reason my application just hangs, nothing being written it just hangs. when I comment out the "Invoke(new UpdateTextCallback(UpdateText));" it works fine. What am I missing?
0
1957
by: milkay | last post by:
<I have code that uses 2 images> the program creates a window and then when u press play, it removes all components in the container. then, i add a NewPanel object. i add mouse listeners and all in all, you should see an image following your mouse. BUT. its only seen after you press play and then resize the window. this leads me to conclude that theres a problem with repaint(). can someone please help? thanks. heres my code: (EnemyShip...
0
9394
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...
1
9338
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8260
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...
1
6803
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 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...
0
6080
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();...
0
4712
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...
1
3322
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
2798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2223
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.