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

background worker and timer locks

Hi all,

I have a GUI application that uses timers

--------------------
TimerCallback readDelegate;
TimerCallback deleteDelegate;
private Timer readTimer;
private Timer deleteTimer;
Apr 3 '06 #1
7 6564
Hi,
Can you post some code, I find it weird that a lock clause does not work,
remember that the sole reason to its existence is for escenarios like yours.
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Apr 3 '06 #2
Hi Ignacio,

This is the method I referred to as heavyProcessing(..)

private SearchResultRecord[] PerformQueryGUI(Resource myResource,
SqlQuery sqlQuery, ref SearchResult searchResult, PropertyName[]
propertyName)
{
lock (lockSqlQueryGUI)
{
MultiStatus multiStatus;
SearchResultRecord[] allRecords;

multiStatus = myResource.Search(sqlQuery);
searchResult = new SearchResult(multiStatus,
propertyName);
allRecords = searchResult.Record;
return allRecords;
}
}

The line that causes problems is -
multiStatus = myResource.Search(sqlQuery);

The exception messages have been -
1. Cannot re-call BeginGetRequestStream/BeginGetResponse while a
previous call is still in progress. System.Net.WebException
2. The request was aborted: The request was canceled.
InvalidOperationException
Bryan

Apr 3 '06 #3
How is lockSqlQueryGUI defined?
Is it unique (single instance) and a reference type?

Laura

"Bryan" <br*********@gmail.com> ha scritto nel messaggio
news:11*********************@v46g2000cwv.googlegro ups.com...
Hi Ignacio,

This is the method I referred to as heavyProcessing(..)

private SearchResultRecord[] PerformQueryGUI(Resource myResource,
SqlQuery sqlQuery, ref SearchResult searchResult, PropertyName[]
propertyName)
{
lock (lockSqlQueryGUI)
{
MultiStatus multiStatus;
SearchResultRecord[] allRecords;

multiStatus = myResource.Search(sqlQuery);
searchResult = new SearchResult(multiStatus,
propertyName);
allRecords = searchResult.Record;
return allRecords;
}
}

The line that causes problems is -
multiStatus = myResource.Search(sqlQuery);

The exception messages have been -
1. Cannot re-call BeginGetRequestStream/BeginGetResponse while a
previous call is still in progress. System.Net.WebException
2. The request was aborted: The request was canceled.
InvalidOperationException
Bryan

Apr 3 '06 #4
private static System.Object lockSqlQueryGUI;
and then in the constructor
lockSqlQueryGUI = new System.Object();

Bryan

Apr 3 '06 #5
Hi,

"Bryan" <br*********@gmail.com> wrote in message
news:11**********************@z34g2000cwc.googlegr oups.com...
private static System.Object lockSqlQueryGUI;
and then in the constructor
lockSqlQueryGUI = new System.Object();


In the static constructor???

usually you declare & init it at the same time:
private static System.Object lockSqlQueryGUI = new System.Object();
See http://www.yoda.arachsys.com/csharp/.../locking.shtml

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation


Apr 3 '06 #6
And you are not creating another instance of the class containing
heavyProcessing method?
If you are, the static object does not protect the access if one thread is
inside the lock
since a new instance of the class has created another lockSqlQueryGUI and
no-one is locking it.

Laura

"Bryan" <br*********@gmail.com> ha scritto nel messaggio
news:11**********************@z34g2000cwc.googlegr oups.com...
private static System.Object lockSqlQueryGUI;
and then in the constructor
lockSqlQueryGUI = new System.Object();

Bryan

Apr 3 '06 #7
Hi again,

To Ignacio : will change it to the way you describe. Didn't think there
was much of a difference!

To Laura: there is only one instance to the class, it's called
MailHelper . In the MainForm I create the instance of MailHelper.

The background worker (I referred to earlier) is called from the
MainForm and the timers are in their own class - MailTimers class.

When them main form is created, I create instances of the MailHelper
and MailTimer.
I pass the instance of MailHelper to the MailTimer.

Via the GUI, the timers are set to run 50 or more times a minute.

Both the delete and read timers use the lockSqlQueryGUI method with
out any problems. It's only when the background worker is called via
the GUI that I have the problem.

Thanks for the help,

Bryan

Apr 3 '06 #8

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

Similar topics

5
by: fooooo | last post by:
This is a network app, written in wxPython and the socket module. This is what I want to happen: GUI app starts. User clicks a button to 'start' the work of the app. When start is pressed, a new...
7
by: John J. Hughes II | last post by:
I have a DataGridView with a TextBoxColumn. I setting the data source to a List<stringvalue in a static class. The list is filled from a background thread. So far all is fine and it works...
6
by: sjoshi | last post by:
I'm able to use the Bacground Worker class to execute task and pain the UI. However I want to be able to execute n tasks in order, say n1, then n2 if there were no errors during n1, n3 so on. ...
8
by: =?Utf-8?B?R3JlZyBMYXJzZW4=?= | last post by:
I'm trying to figure out how to modify a panel (panel1) from a backgroundworker thread. But can't get the panel to show the new controls added by the backgroundwork task. Here is my code. In...
4
by: Jesse Aufiero | last post by:
I'm wondering what the rule is on how to assure that the background worker 'DoWork' routine is truly running entirely in the background. My DoWork routine calls another procedure which resides in...
4
by: csharpula csharp | last post by:
Hello, Can you please tell me if I should use the background worker in the following way: if (worker.IsBusy) worker.CancelAsync(); (or I can avoid this if)? And in case I want to restart the...
8
by: Analizer1 | last post by:
From what im reading about backgroundworker thread it seems it can only have 1 thread at a time is this correct tks
7
by: csharpula csharp | last post by:
Hello, I got a question regarding the usage of background worker. How can I run few threads via background worker with different objects as parameter each time. I understood that I can't do...
1
by: Infog | last post by:
I am trying to code a simple background workers class without needing to use the backgroundworker object on a form. This would allow me to use a background worker in any class without writing much...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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
Oralloy
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,...
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.