PC Review


Reply
Thread Tools Rate Thread

backgroundworker in windows service or console application

 
 
=?Utf-8?B?TWljaGVsIE1lZXg=?=
Guest
Posts: n/a
 
      21st Oct 2005
Is it true that a backgroundworker will only work in winforms applications,
and not in console applications and/or windows services ?

If have an object (Task) that instantiates different backgroundworker
instances. If I start the task object from a windows form, it works fine. If
I do this from a windows service, it will start the Task object, but will
never fire my real object.

Any help would be nice.

 
Reply With Quote
 
 
 
 
Alvin Bruney - ASP.NET MVP
Guest
Posts: n/a
 
      21st Oct 2005
Although I haven't tried different environments, I don't see a reason why
this would be true. The backgroundworker is a wrapper for threads - threads
work everywhere. Now you may have some issues with webforms due to the
timing of the long running tasks and the availability of the context object
however that is not related to it functioning correctly. I'll check tonight
to make sure - there's always a chance that I'm wrong.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------



"Michel Meex" <(E-Mail Removed)> wrote in message
news:F7202F0E-FEBA-4FEB-8662-(E-Mail Removed)...
> Is it true that a backgroundworker will only work in winforms

applications,
> and not in console applications and/or windows services ?
>
> If have an object (Task) that instantiates different backgroundworker
> instances. If I start the task object from a windows form, it works fine.

If
> I do this from a windows service, it will start the Task object, but will
> never fire my real object.
>
> Any help would be nice.
>



 
Reply With Quote
 
 
 
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      23rd Oct 2005

"Michel Meex" <(E-Mail Removed)> wrote in message
news:F7202F0E-FEBA-4FEB-8662-(E-Mail Removed)...
> Is it true that a backgroundworker will only work in winforms
> applications,
> and not in console applications and/or windows services ?
>
> If have an object (Task) that instantiates different backgroundworker
> instances. If I start the task object from a windows form, it works fine.
> If
> I do this from a windows service, it will start the Task object, but will
> never fire my real object.
>
> Any help would be nice.
>


The BackgroundWorker cannot be used from windows services, it is designed
to be used in combination with a UI thread, that is a thread that has a
message queue, windows services don't have a UI thread or a thread that
pumps the message queue.

Willy.


 
Reply With Quote
 
=?Utf-8?B?TWljaGVsIE1lZXg=?=
Guest
Posts: n/a
 
      24th Oct 2005
Willy,

Thanks for your answer. It's not documented however. Do you know if there's
a simple way to achieve the same functionality in a windows service ?

Michel


"Willy Denoyette [MVP]" wrote:

>
> "Michel Meex" <(E-Mail Removed)> wrote in message
> news:F7202F0E-FEBA-4FEB-8662-(E-Mail Removed)...
> > Is it true that a backgroundworker will only work in winforms
> > applications,
> > and not in console applications and/or windows services ?
> >
> > If have an object (Task) that instantiates different backgroundworker
> > instances. If I start the task object from a windows form, it works fine.
> > If
> > I do this from a windows service, it will start the Task object, but will
> > never fire my real object.
> >
> > Any help would be nice.
> >

>
> The BackgroundWorker cannot be used from windows services, it is designed
> to be used in combination with a UI thread, that is a thread that has a
> message queue, windows services don't have a UI thread or a thread that
> pumps the message queue.
>
> Willy.
>
>
>

 
Reply With Quote
 
Alvin Bruney - ASP.NET MVP
Guest
Posts: n/a
 
      24th Oct 2005

> > The BackgroundWorker cannot be used from windows services, it is

designed
> > to be used in combination with a UI thread

true, true. i forgot that part.

> Thanks for your answer. It's not documented however. Do you know if

there's
> a simple way to achieve the same functionality in a windows service ?

You can use a simple thread to accomplish this task.

--
Regards,
Alvin Bruney [MVP ASP.NET]

[Shameless Author plug]
The Microsoft Office Web Components Black Book with .NET
Now Available @ www.lulu.com/owc
Forth-coming VSTO.NET - Wrox/Wiley 2006
-------------------------------------------------------



"Michel Meex" <(E-Mail Removed)> wrote in message
news:EFDE5223-06E8-4D5B-96F3-(E-Mail Removed)...
> Willy,
>
> Thanks for your answer. It's not documented however. Do you know if

there's
> a simple way to achieve the same functionality in a windows service ?
>
> Michel
>
>
> "Willy Denoyette [MVP]" wrote:
>
> >
> > "Michel Meex" <(E-Mail Removed)> wrote in message
> > news:F7202F0E-FEBA-4FEB-8662-(E-Mail Removed)...
> > > Is it true that a backgroundworker will only work in winforms
> > > applications,
> > > and not in console applications and/or windows services ?
> > >
> > > If have an object (Task) that instantiates different backgroundworker
> > > instances. If I start the task object from a windows form, it works

fine.
> > > If
> > > I do this from a windows service, it will start the Task object, but

will
> > > never fire my real object.
> > >
> > > Any help would be nice.
> > >

> >
> > The BackgroundWorker cannot be used from windows services, it is

designed
> > to be used in combination with a UI thread, that is a thread that has a
> > message queue, windows services don't have a UI thread or a thread that
> > pumps the message queue.
> >
> > Willy.
> >
> >
> >



 
Reply With Quote
 
Willy Denoyette [MVP]
Guest
Posts: n/a
 
      24th Oct 2005
Michel,

If you are looking for the exact same functionality, stop looking, Windows
Services should not have UI threads, so there is no need to "Post" messages
to the UI thread's message loop.
However, if you are looking for a way to run a short running function on a
separate thread, you'll have to look at the ThreadPool class, for functions
that run for a long period (say > 2-5 seconds) you better use the Thread
class.

Willy.

"Michel Meex" <(E-Mail Removed)> wrote in message
news:EFDE5223-06E8-4D5B-96F3-(E-Mail Removed)...
> Willy,
>
> Thanks for your answer. It's not documented however. Do you know if
> there's
> a simple way to achieve the same functionality in a windows service ?
>
> Michel
>
>
> "Willy Denoyette [MVP]" wrote:
>
>>
>> "Michel Meex" <(E-Mail Removed)> wrote in message
>> news:F7202F0E-FEBA-4FEB-8662-(E-Mail Removed)...
>> > Is it true that a backgroundworker will only work in winforms
>> > applications,
>> > and not in console applications and/or windows services ?
>> >
>> > If have an object (Task) that instantiates different backgroundworker
>> > instances. If I start the task object from a windows form, it works
>> > fine.
>> > If
>> > I do this from a windows service, it will start the Task object, but
>> > will
>> > never fire my real object.
>> >
>> > Any help would be nice.
>> >

>>
>> The BackgroundWorker cannot be used from windows services, it is
>> designed
>> to be used in combination with a UI thread, that is a thread that has a
>> message queue, windows services don't have a UI thread or a thread that
>> pumps the message queue.
>>
>> Willy.
>>
>>
>>



 
Reply With Quote
 
=?Utf-8?B?TWljaGVsIE1lZXg=?=
Guest
Posts: n/a
 
      25th Oct 2005
Thanks for your answer. I wasn't aware of the fact that the backgroundworker
was only ment for UI purposes. In my case, I only need to start processes for
a short time at a scheduled moment. So I am going to implement the Thread
class like I did in the past. It would have been very nice if there was some
backgroundworker functionality for non-ui purposes. Saves me some development
time.

Regards,
Michel

"Willy Denoyette [MVP]" wrote:

> Michel,
>
> If you are looking for the exact same functionality, stop looking, Windows
> Services should not have UI threads, so there is no need to "Post" messages
> to the UI thread's message loop.
> However, if you are looking for a way to run a short running function on a
> separate thread, you'll have to look at the ThreadPool class, for functions
> that run for a long period (say > 2-5 seconds) you better use the Thread
> class.
>
> Willy.
>
> "Michel Meex" <(E-Mail Removed)> wrote in message
> news:EFDE5223-06E8-4D5B-96F3-(E-Mail Removed)...
> > Willy,
> >
> > Thanks for your answer. It's not documented however. Do you know if
> > there's
> > a simple way to achieve the same functionality in a windows service ?
> >
> > Michel
> >
> >
> > "Willy Denoyette [MVP]" wrote:
> >
> >>
> >> "Michel Meex" <(E-Mail Removed)> wrote in message
> >> news:F7202F0E-FEBA-4FEB-8662-(E-Mail Removed)...
> >> > Is it true that a backgroundworker will only work in winforms
> >> > applications,
> >> > and not in console applications and/or windows services ?
> >> >
> >> > If have an object (Task) that instantiates different backgroundworker
> >> > instances. If I start the task object from a windows form, it works
> >> > fine.
> >> > If
> >> > I do this from a windows service, it will start the Task object, but
> >> > will
> >> > never fire my real object.
> >> >
> >> > Any help would be nice.
> >> >
> >>
> >> The BackgroundWorker cannot be used from windows services, it is
> >> designed
> >> to be used in combination with a UI thread, that is a thread that has a
> >> message queue, windows services don't have a UI thread or a thread that
> >> pumps the message queue.
> >>
> >> Willy.
> >>
> >>
> >>

>
>
>

 
Reply With Quote
 
William Stacey [MVP]
Guest
Posts: n/a
 
      25th Oct 2005
It works fine in a console or service app with no forms. The delegates are
run on thread pool threads instead of the UI thread. So there is nothing
special going on, just delegates, BeginInvoke, and events. Try it yourself.

--
William Stacey [MVP]

"Michel Meex" <(E-Mail Removed)> wrote in message
news:2BA92078-DE78-4E14-A273-(E-Mail Removed)...
> Thanks for your answer. I wasn't aware of the fact that the
> backgroundworker
> was only ment for UI purposes. In my case, I only need to start processes
> for
> a short time at a scheduled moment. So I am going to implement the Thread
> class like I did in the past. It would have been very nice if there was
> some
> backgroundworker functionality for non-ui purposes. Saves me some
> development
> time.
>
> Regards,
> Michel
>
> "Willy Denoyette [MVP]" wrote:
>
>> Michel,
>>
>> If you are looking for the exact same functionality, stop looking,
>> Windows
>> Services should not have UI threads, so there is no need to "Post"
>> messages
>> to the UI thread's message loop.
>> However, if you are looking for a way to run a short running function on
>> a
>> separate thread, you'll have to look at the ThreadPool class, for
>> functions
>> that run for a long period (say > 2-5 seconds) you better use the Thread
>> class.
>>
>> Willy.
>>
>> "Michel Meex" <(E-Mail Removed)> wrote in message
>> news:EFDE5223-06E8-4D5B-96F3-(E-Mail Removed)...
>> > Willy,
>> >
>> > Thanks for your answer. It's not documented however. Do you know if
>> > there's
>> > a simple way to achieve the same functionality in a windows service ?
>> >
>> > Michel
>> >
>> >
>> > "Willy Denoyette [MVP]" wrote:
>> >
>> >>
>> >> "Michel Meex" <(E-Mail Removed)> wrote in message
>> >> news:F7202F0E-FEBA-4FEB-8662-(E-Mail Removed)...
>> >> > Is it true that a backgroundworker will only work in winforms
>> >> > applications,
>> >> > and not in console applications and/or windows services ?
>> >> >
>> >> > If have an object (Task) that instantiates different
>> >> > backgroundworker
>> >> > instances. If I start the task object from a windows form, it works
>> >> > fine.
>> >> > If
>> >> > I do this from a windows service, it will start the Task object, but
>> >> > will
>> >> > never fire my real object.
>> >> >
>> >> > Any help would be nice.
>> >> >
>> >>
>> >> The BackgroundWorker cannot be used from windows services, it is
>> >> designed
>> >> to be used in combination with a UI thread, that is a thread that has
>> >> a
>> >> message queue, windows services don't have a UI thread or a thread
>> >> that
>> >> pumps the message queue.
>> >>
>> >> Willy.
>> >>
>> >>
>> >>

>>
>>
>>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Keeping application responsive with BackgroundWorker Joseph Geretz Microsoft C# .NET 4 9th Jul 2007 07:57 PM
Delagate vs. BackGroundWorker vs. Web Service =?Utf-8?B?ZGJhMTIz?= Microsoft C# .NET 0 26th Jul 2006 07:25 PM
BackgroundWorker and 'freezing' application =?Utf-8?B?U2ViYXN0aWFuIENyZXdl?= Microsoft VB .NET 2 24th Mar 2006 10:26 AM
How to run a console application without showing the console screen? Tee Microsoft C# .NET 2 11th Feb 2005 07:22 AM
How to set a fixed line in a console application liek UNIX console AA Microsoft C# .NET 1 6th Dec 2003 03:23 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:00 PM.