473,378 Members | 1,119 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,378 software developers and data experts.

Problem with a worker thread causing app to not respond

Hello all,

I have an application that is used for porting data from one system to
another. There is a scan button that starts a new thread that does the
processing.
Everything seems to work fine unless the application loses focus. If the
app loses focus the form will no longer refresh and it just sits there. If
I click where one of the buttons used to be the app just says not responding
in the title bar.

I am new to using threads so please be very descriptive in your reply.

Here is the code that is executed when the scan button is clicked:
System.Threading.ThreadStart ts = new
System.Threading.ThreadStart(this.runScan);
System.Threading.Thread scanthread = new System.Threading.Thread(ts);
scanthread.IsBackground = true;
scanthread.Start();

Thanks

Nov 16 '05 #1
5 1606

1) Does the app work if it does not lose focus?

2) Are you sharing data between the worker thread and the GUI? If so how?

--Richard

"Dante" wrote:
Hello all,

I have an application that is used for porting data from one system to
another. There is a scan button that starts a new thread that does the
processing.
Everything seems to work fine unless the application loses focus. If the
app loses focus the form will no longer refresh and it just sits there. If
I click where one of the buttons used to be the app just says not responding
in the title bar.

I am new to using threads so please be very descriptive in your reply.

Here is the code that is executed when the scan button is clicked:
System.Threading.ThreadStart ts = new
System.Threading.ThreadStart(this.runScan);
System.Threading.Thread scanthread = new System.Threading.Thread(ts);
scanthread.IsBackground = true;
scanthread.Start();

Thanks

Nov 16 '05 #2
Can you post the code from the thread function (runScan) as well please

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<ck**********@news.xmission.com>

Hello all,

I have an application that is used for porting data from one system to
another. There is a scan button that starts a new thread that does the
processing.
Everything seems to work fine unless the application loses focus. If the
app loses focus the form will no longer refresh and it just sits there. If
I click where one of the buttons used to be the app just says not responding
in the title bar.

I am new to using threads so please be very descriptive in your reply.

Here is the code that is executed when the scan button is clicked:
System.Threading.ThreadStart ts = new
System.Threading.ThreadStart(this.runScan);
System.Threading.Thread scanthread = new System.Threading.Thread(ts);
scanthread.IsBackground = true;
scanthread.Start();

Thanks


---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.771 / Virus Database: 518 - Release Date: 28/09/2004

[microsoft.public.dotnet.languages.csharp]
Nov 16 '05 #3
Here is the runScan function:

==================================

btn_scan.Enabled = false;
btn_update.Enabled = false;
disableMenuItems();
pnl_progress.Visible = true;
pnl_progress.BringToFront();
lbl_progress.Text = "Gathering data... Please wait.";
pnl_progress.Refresh();

//Based on the tab that is selected, call the appropriate function
ScanFunctions sf = new ScanFunctions(this);
switch (this.tabs.SelectedTab.Name)
{
case "tabAccounts":
sf.scanAccounts();
break;
case "tabContacts":
sf.scanContacts();
break;
case "tabNewContracts":
sf.scanNewContracts();
break;
case "tabEquipment":
sf.scanEquipment();
break;
case "tabCalls":
sf.scanCalls();
break;
case "tabMeters":
sf.scanMeters();
break;
case "tabInvoices":
sf.scanInvoices();
break;
}

btn_scan.Enabled = true;
btn_update.Enabled = true;
statusBar1.Panels[0].Text = "";
enableMenuItems();
pnl_progress.Visible = false;
Cursor.Current = System.Windows.Forms.Cursors.Default;

==============================

the ScanFunctions class makes a connection to both a SQL server and a
web service where it gathers data and then populates two ListViews on
the main form (this).

Thanks,
Dante

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #4
OK, the problem is you are updating the UI from teh work thread - in WIndows the only thread that can work on the UI is the thread that created the UI elements. All of the interaction with the form and it's controls needs to be marshalled back to the UI thread which can be done via the BeginInvoke method of the Control class.

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/<e4**************@TK2MSFTNGP09.phx.gbl>

Here is the runScan function:

==================================

btn_scan.Enabled = false;
btn_update.Enabled = false;
disableMenuItems();
pnl_progress.Visible = true;
pnl_progress.BringToFront();
lbl_progress.Text = "Gathering data... Please wait.";
pnl_progress.Refresh();

//Based on the tab that is selected, call the appropriate function
ScanFunctions sf = new ScanFunctions(this);
switch (this.tabs.SelectedTab.Name)
{
case "tabAccounts":
sf.scanAccounts();
break;
case "tabContacts":
sf.scanContacts();
break;
case "tabNewContracts":
sf.scanNewContracts();
break;
case "tabEquipment":
sf.scanEquipment();
break;
case "tabCalls":
sf.scanCalls();
break;
case "tabMeters":
sf.scanMeters();
break;
case "tabInvoices":
sf.scanInvoices();
break;
}

btn_scan.Enabled = true;
btn_update.Enabled = true;
statusBar1.Panels[0].Text = "";
enableMenuItems();
pnl_progress.Visible = false;
Cursor.Current = System.Windows.Forms.Cursors.Default;

==============================

the ScanFunctions class makes a connection to both a SQL server and a
web service where it gathers data and then populates two ListViews on
the main form (this).

Thanks,
Dante

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.771 / Virus Database: 518 - Release Date: 28/09/2004

[microsoft.public.dotnet.languages.csharp]
Nov 16 '05 #5
Dan Telschow <da*****@hotmail.com> wrote:
Here is the runScan function:


<snip>

As Richard said, the problem is updating the UI from a non-UI thread.

See http://www.pobox.com/~skeet/csharp/t...winforms.shtml for more
information about this.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6

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

Similar topics

1
by: Tristan Ludowyk | last post by:
Hi, In my application I have a worker thread which goes and sends faxes using winXPs FAXCOMEXLib API. When a fax is complete or fails, an event is triggered. In this handler I save the result...
12
by: Joey Powell | last post by:
Re: Original post = Windows forms - how do I get them to render/update properly? from August 22. Okay I am making some progress with being able to use delegates to run my shelled processes on...
4
by: Madhu Gopinathan | last post by:
Hi All, I am faced with a horrible hang problem. I have a COM exe server that executes some tasks. The task execution manager is a thread that manages the pool of threads, which is 4 per processor....
3
by: Jack Fox | last post by:
While stress-testing our ASP.NET app, we discovered a flaw in our test set-up, which also reveals a flaw in our ASP.NET configuration that we do not know how to address. We simulated too...
6
by: Joe Jax | last post by:
I have an object that spawns a worker thread to process one of its methods. That method processes methods on a collection of other objects. During this processing, a user may request to cancel the...
4
by: Al Norman | last post by:
We have two separate DLLs that do not interact (directly, at least). One is an MFC extension DLL that was built back in VC++ 6 days (but has been recompiled with VS2005). The other is a DLL that...
1
by: Ryan Liu | last post by:
Hi, I have a 100 clients/ one server application, use ugly one thread pre client approach. And both side user sync I/O. I frequently see the error on server side(client side code is same, but...
2
by: =?Utf-8?B?anAybXNmdA==?= | last post by:
Using Visual Studio 2005 Professional: I have two thread routines in one project at this time. One came from me dropping a BackgroundWorker component on my form and setting the properties for...
1
by: raghudr | last post by:
Hi all, I am displaying a splash screen for which i have created a thread.Since my whole project is launched by windows service and that service will start automatically at the start of the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.