By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,168 Members | 1,492 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,168 IT Pros & Developers. It's quick & easy.

background worker and timer locks

P: n/a
Hi all,

I have a GUI application that uses timers

--------------------
TimerCallback readDelegate;
TimerCallback deleteDelegate;
private Timer readTimer;
private Timer deleteTimer;
Apr 3 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
private static System.Object lockSqlQueryGUI;
and then in the constructor
lockSqlQueryGUI = new System.Object();

Bryan

Apr 3 '06 #5

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.