473,666 Members | 2,728 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Simple app....silly question?

I have a Windows Forms app that is intended to launch via the SendTo
feature. I want it to perform work (in the background) while updating
a progress bar in the main window.

The problem: I want this to run without any user interaction (except
for launching the app via SendTo).
The form is created via an Application.Run (new myForm()) call, which
then proceeds through the form constructor.

When the constructor returns and the form is displayed, I have no way
of instructing the application to "begin" work. As a workaround, I
temporarily placed a button on the form for the user to initiate work.

I must be missing something. This seems like it would be trivial to
implement. I was considering using a timer as a hack, but surely
there is a better option. Launching a worker thread before exiting
the constructor doesn't strike me as a very good idea either...

Any ideas?

Oct 29 '08 #1
4 1246
On Wed, 29 Oct 2008 11:01:25 -0700, David Bonnell <db******@gmail .com>
wrote:
I have a Windows Forms app that is intended to launch via the SendTo
feature. I want it to perform work (in the background) while updating
a progress bar in the main window.

[...]
I must be missing something. This seems like it would be trivial to
implement. I was considering using a timer as a hack, but surely
there is a better option. Launching a worker thread before exiting
the constructor doesn't strike me as a very good idea either...

Any ideas?
I'm not sure I understand the question. Do you not want the form to
display at all? Or do you simply want things to happen while the form is
displayed without the user having to specifically interact with the form?

If the latter, then I don't see what your objection to starting a worker
thread in the constructor is -- that should work fine -- but if you don't
like that, you could instead do something similar in the form's OnLoad()
or OnShown() method. You'll definitely want to use a worker thread of
_some_ form, such as BackgroundWorke r, to ensure that the UI remains
responsive.

Pete
Oct 29 '08 #2
>
I'm not sure I understand the question. *Do you not want the form to *
display at all? *Or do you simply want things to happen while the form is *
displayed without the user having to specifically interact with the form?
I want the form to display (the form should consist of only a progress
bar and possibly a status label).
As work is being done (some file manipulation), I want the progress
bar to update to give the user some feedback that the task is being
completed.
Once the task is complete, I want the application to exit.
If the latter, then I don't see what your objection to starting a worker *
thread in the constructor is -- that should work fine -- but if you don't*
like that, you could instead do something similar in the form's OnLoad() *
or OnShown() method. *
I guess I'm not a fan of doing too much in a constructor. Probably
more a lack of understanding than anything...
OnLoad/Shown seems like a good idea. I'll give it a try and see what
shakes loose.

Thanks,
Dave

Oct 29 '08 #3
On Wed, 29 Oct 2008 11:40:52 -0700, David Bonnell <db******@gmail .com>
wrote:
[...]
I guess I'm not a fan of doing too much in a constructor. Probably
more a lack of understanding than anything...
OnLoad/Shown seems like a good idea. I'll give it a try and see what
shakes loose.
The only argument I can think of against initializing the worker thread in
the constructor is that if the worker thread should get to a point where
it wants to update the UI before the form has actually gotten a chance to
be fully initialized, then the call to Invoke() (whether explicit in your
code or implicit via a BackgroundWorke r or similar) could fail in the
worker thread.

I suppose that might be a consideration here. It depends on how you
implement the worker thread. But from a more general point of view, as
long as you're not doing something that will lead to an illegal operation,
I don't think that it's necessarily a bad thing to put initialization code
in the constructor. It has to run _sometime_, and the constructor is in
fact a place where things are supposed to get initialized. :)

But, OnShown() should work fine...it's pretty much the latest method/event
that gets called/raised as the form is being created and run, other than
OnPaint() (which would be a silly place to put initialization :) ).

Pete
Oct 29 '08 #4
>
I suppose that might be a consideration here. *It depends on how you *
implement the worker thread. *But from a more general point of view, as*
long as you're not doing something that will lead to an illegal operation, *
I don't think that it's necessarily a bad thing to put initialization code *
in the constructor. *It has to run _sometime_, and the constructor is in *
fact a place where things are supposed to get initialized. *:)
OnShown worked like a charm. Thanks for the help.

I suspect that in this case it would work fine in the
constructor...b ut I am my own worst enemy. A month from now I'd
probably add more initialization to the constructor and miss some GUI
updates from the worker thread as a result.

Dave

Oct 30 '08 #5

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

Similar topics

3
1755
by: Jim Heavey | last post by:
Hello I am working through a littel tutorial on XSL and I have a "simple" question. I am wanting to build a table with headings of the lement names. The tutorial show that I am to use the "name(.)" to retrieve the element name. The example show this in a "for-each" loop, but I am not wanting to build a entire table with these name, just the headings. I tried using the follows: <th> <xsl:value-of...
51
8261
by: Alan | last post by:
hi all, I want to define a constant length string, say 4 then in a function at some time, I want to set the string to a constant value, say a below is my code but it fails what is the correct code? many thx!
2
1186
by: RSH | last post by:
Hi, i have a situation where I have a VB .Net Module built that contains all of the functions I need. I now need to add a form to the project and i need the form to sdisplay and the module code to write to the form. I am having trouble figuring out how to do this. Basically, I have Form1 which contains a button and a TextBox. Module1 contains a function called Function1. I want to attach an event to the button which will call...
2
1168
by: Soren Kuula | last post by:
Looks like a silly question? I'm in doubt! - the Recommendation does it (anyType / anySimple type) - it's possible to restrict away all optional elements and attributes from a mixed complex type. If doing that on a type where all elements and attributes are optional, does that leave one with the equivalent of anySimpleType, then? Soren
1
2015
by: rolfejr | last post by:
I have what I think is a simple question but I am finding nothing but complicated answers. I have a web site running on IIS6. One directory used to use an alternate account as the anonymous user (not the IUSR_ServerName account) to connect to a database, etc. Now the pages in that directory no longer do anything special and I just want to start using the default IUSR_ServerName account again. I put that account back in, but what do I...
6
2335
by: Paul | last post by:
Hi All, Framework 1.1 listbox control unable to DataBind I've been googling for an answer to this query that appears quite a lot, but none, it seem, answers my problem directly. I am populating a listbox with an array of very simple "Country" objects via a WebService. The Country class contains CountryID,TLDs and Name properties each of which have a getter and setter (I found that properties without
11
1382
by: rh0dium | last post by:
Hi all, I have a simple list to which I want to append another tuple if element 0 is not found anywhere in the list. element = ('/smsc/chp/aztec/padlib/5VT.Cat', '/smsc/chp/aztec/padlib', '5VT.Cat', (33060)) element1 = ('/smsc/chp/aztec/padlib/5VT.Cat2',
14
1372
Airslash
by: Airslash | last post by:
Hello, Perhaps it might seem a silly question to some but I want to know the following: I'm handy with C++. I won't claim to be an expert, but I can get most common things done in C++. Now I want to focus a bit more on C itself. I've tried getting my hands on the C manual book, but unfortunalty they bookstore couldn't get it anymore. So my little question is : how hard is it to switch to learning and using C if you're moderate in C++...
5
1753
by: Ibys | last post by:
Hi, i am just starting to learn javascript, so i am probably doing something very simple wrong. i have read a lot of articles on maths in java, but cant find anything simple enough for my problem. I am looking for how to get an IF statement to give me the correct output. I am trying to get it to give me a result for a weeks pay, taking that the code worked before i tried to add the IF statement, to make it that if HoursWorked >= 20, the rate of...
0
8438
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8348
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8863
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8636
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6187
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5660
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4356
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2765
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2004
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.