System.Threading.Timer and Crystal Reports

R

Ryan Gregg

I've got a background service running that needs to check a database
periodically and print reports whenever it finds that the data has changed.

I've built a class library that scans the database for the changes, and then
generates a report using the VS.NET 2003 version of Crystal Reports, and
prints the report. It works just fine when I use it in a single threaded
environment.

However, when I build an application that uses a System.Threading.Timer
object to run this method on a set schedule, anytime I try to work with the
report objects, the thread just hangs and never comes back

Is there some threading issue in Crystal Reports that anyone knows about, or
better yet, is there some way in C# to get back on the main execution thread
so that I can work with the reports there, avoiding this problem? Remember,
this is all running in a service or a console app, so I don't have a windows
form I can call Invoke or BeginInvoke on.

Thanks!

Ryan Gregg
 
P

Philip Rieck

Two things to check:

1. Make sure you have the [STAThread] attribute above your main. Crystal
ultimately calls into COM objects, and they may require single-threaded
apartment model.

2. If you're running as a service when the crashes happen, try allowing the
service to interact with the desktop. (it's possible it needs graphic dc's)
 
R

Ryan Gregg

Thanks for your reply Philip. However, I've got the STAThread attribute on
my main method. I'm actually running the service right now (in order to
debug it) through a console application. I wrote a class library that does
all the service actions, and then I have two other projects that I can use
to run it, either as a console window or as a Win32 service. It behaves the
same way regardless of how I run it.

I created a 3 test cases using a Console program and different threading
aspects, and it never has any problems there. However, it always dies in my
real application.

Any other ideas?

Thanks again.

Ryan Gregg


Philip Rieck said:
Two things to check:

1. Make sure you have the [STAThread] attribute above your main. Crystal
ultimately calls into COM objects, and they may require single-threaded
apartment model.

2. If you're running as a service when the crashes happen, try allowing the
service to interact with the desktop. (it's possible it needs graphic dc's)



Ryan Gregg said:
I've got a background service running that needs to check a database
periodically and print reports whenever it finds that the data has changed.

I've built a class library that scans the database for the changes, and then
generates a report using the VS.NET 2003 version of Crystal Reports, and
prints the report. It works just fine when I use it in a single threaded
environment.

However, when I build an application that uses a System.Threading.Timer
object to run this method on a set schedule, anytime I try to work with the
report objects, the thread just hangs and never comes back

Is there some threading issue in Crystal Reports that anyone knows
about,
or
better yet, is there some way in C# to get back on the main execution thread
so that I can work with the reports there, avoiding this problem? Remember,
this is all running in a service or a console app, so I don't have a windows
form I can call Invoke or BeginInvoke on.

Thanks!

Ryan Gregg
 
P

Philip Rieck

I wish I had more ideas for you. If you have a simple repro case, feel free
to email it to me and I'll take a look. Otherwise, I'm of no help to you at
the moment -- Crystal is just not my forte. (in fact, I avoid it if I can).
Good luck!


Ryan Gregg said:
Thanks for your reply Philip. However, I've got the STAThread attribute on
my main method. I'm actually running the service right now (in order to
debug it) through a console application. I wrote a class library that does
all the service actions, and then I have two other projects that I can use
to run it, either as a console window or as a Win32 service. It behaves the
same way regardless of how I run it.

I created a 3 test cases using a Console program and different threading
aspects, and it never has any problems there. However, it always dies in my
real application.

Any other ideas?

Thanks again.

Ryan Gregg


Philip Rieck said:
Two things to check:

1. Make sure you have the [STAThread] attribute above your main. Crystal
ultimately calls into COM objects, and they may require single-threaded
apartment model.

2. If you're running as a service when the crashes happen, try allowing the
service to interact with the desktop. (it's possible it needs graphic dc's)



Ryan Gregg said:
I've got a background service running that needs to check a database
periodically and print reports whenever it finds that the data has changed.

I've built a class library that scans the database for the changes,
and
then
generates a report using the VS.NET 2003 version of Crystal Reports, and
prints the report. It works just fine when I use it in a single threaded
environment.

However, when I build an application that uses a System.Threading.Timer
object to run this method on a set schedule, anytime I try to work
with
the
report objects, the thread just hangs and never comes back

Is there some threading issue in Crystal Reports that anyone knows
about,
or
better yet, is there some way in C# to get back on the main execution thread
so that I can work with the reports there, avoiding this problem? Remember,
this is all running in a service or a console app, so I don't have a windows
form I can call Invoke or BeginInvoke on.

Thanks!

Ryan Gregg
 
R

Ryan Gregg

I know what you mean :) Unforutnately I haven't been able to reproduce the
problem in a simple fashion. In fact, the project I've been working with
appears to work just fine on another development machine I have. I'm now
wondering if it is some sort of side effect of having CrystalReports 8.5
installed.

Thanks again Philip!

Ryan Gregg

Philip Rieck said:
I wish I had more ideas for you. If you have a simple repro case, feel free
to email it to me and I'll take a look. Otherwise, I'm of no help to you at
the moment -- Crystal is just not my forte. (in fact, I avoid it if I can).
Good luck!


Ryan Gregg said:
Thanks for your reply Philip. However, I've got the STAThread attribute on
my main method. I'm actually running the service right now (in order to
debug it) through a console application. I wrote a class library that does
all the service actions, and then I have two other projects that I can use
to run it, either as a console window or as a Win32 service. It behaves the
same way regardless of how I run it.

I created a 3 test cases using a Console program and different threading
aspects, and it never has any problems there. However, it always dies
in
my
real application.

Any other ideas?

Thanks again.

Ryan Gregg


Philip Rieck said:
Two things to check:

1. Make sure you have the [STAThread] attribute above your main. Crystal
ultimately calls into COM objects, and they may require single-threaded
apartment model.

2. If you're running as a service when the crashes happen, try
allowing
the
service to interact with the desktop. (it's possible it needs graphic dc's)



I've got a background service running that needs to check a database
periodically and print reports whenever it finds that the data has
changed.

I've built a class library that scans the database for the changes, and
then
generates a report using the VS.NET 2003 version of Crystal Reports, and
prints the report. It works just fine when I use it in a single threaded
environment.

However, when I build an application that uses a System.Threading.Timer
object to run this method on a set schedule, anytime I try to work with
the
report objects, the thread just hangs and never comes back

Is there some threading issue in Crystal Reports that anyone knows about,
or
better yet, is there some way in C# to get back on the main execution
thread
so that I can work with the reports there, avoiding this problem?
Remember,
this is all running in a service or a console app, so I don't have a
windows
form I can call Invoke or BeginInvoke on.

Thanks!

Ryan Gregg
 

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