473,385 Members | 1,838 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 1235
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 BackgroundWorker, 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 BackgroundWorker 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...but 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
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...
51
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...
2
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...
2
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...
1
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...
6
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...
11
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',...
14
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...
5
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...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.