windows service stops responding

R

roger_27

I'm developing a windows service that has a timer (System.Timer.Timer) and
adds some data to a database, and exports it all to a dataset, which is then
written as XML.

everything works great, except for when it gets to the .fill method in the
dataset, then it just hangs. it sits there. nothing happens. I've had it sit
there 15 minutes and no response from the service. I know that this is a
large dataset (20,000- 100,000 rows) but this exact identical code works fine
in a winform environment. anyone have any ideas?
 
M

Michael J. Ryan

I'm developing a windows service that has a timer (System.Timer.Timer) and
adds some data to a database, and exports it all to a dataset, which is then
written as XML.

everything works great, except for when it gets to the .fill method in the
dataset, then it just hangs. it sits there. nothing happens. I've had it sit
there 15 minutes and no response from the service. I know that this is a
large dataset (20,000- 100,000 rows) but this exact identical code works fine
in a winform environment. anyone have any ideas?

Are you locking class level and other resources as needed? Sounds like a race
condition or other resource contention issue is most likely... Honestly, you
should probably use a single threaded worker loop, opposed to a timer, where
depending on the setting could backup multiple event thread triggering.


/////////////////////////////////////////////////////////
public void Start() {
lock(this._lock) {
if (this.Worker != null) return; //already running
this.Worker = new Thread(new ThreadStart(this.Work))
}
}

public void Stop() {
lock(this._lock) {
if (this.Worker != null)
this.worker.Abort();
}
}

private void Work() {
try {
var nextRun = DateTime.MinValue;
while(true) {
if (nextRun < DateTime.Now) {
Foo(); //do your work
nextRun = DateTime.Now.AddMinutes(10); //run again in 10 min
}
Thread.Sleep(1000); //sleep for a second, reduce loop overhead
}
} catch(ThreadAbortException) {
//do nothing - closing service
} catch (Exception err) {
LogException(err);
} finally {
this.Worker = null; //clear worker thread reference
}
}
//////////////////////////////////////////////////////////

Beyond this...

Do you have a profiler/trace/logging followup that shows it's definitly
hanging on the .Fill? Does it hang the first time or in followups (could the
file be locked from a prior run? Whatabout permissions (what user, if any is
the service running as?) local or remote directory share? Does it eventually
complete?
 
R

Rajoo Sharma

roger_27 said:
I'm developing a windows service that has a timer (System.Timer.Timer) and
adds some data to a database, and exports it all to a dataset, which is then
written as XML.

everything works great, except for when it gets to the .fill method in the
dataset, then it just hangs. it sits there. nothing happens. I've had it sit
there 15 minutes and no response from the service. I know that this is a
large dataset (20,000- 100,000 rows) but this exact identical code works fine
in a winform environment. anyone have any ideas?

Are you sure the code you are running in the windows service is properly
referenced? If it is not properly referenced than the garbage collector
will collect it...

http://www.hd720i.com/Category/Windows/Windows Server/32-1.aspx
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top