473,325 Members | 2,816 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,325 software developers and data experts.

progress from Blocking method? or blocking main thread with async method??

hi ,

I'm in a slight dilemma.

I have an updater program that checks for pending updates and
downloads them if the users chooses to.

Since i dont need a windows form to check if there is an update , I
dont use a form unless i have two. This , creates either one of two
problems. When i'm downloading asynchonously , the main thread exits!
Or if use a blocked download , how do i display progress!?

In the updater.DownloadUpdates() , i show a reusable ProgressForm ,
and update it in the downloadProgress changed event, but it just shows
and nothing happens and the App never closes!?

[STAThread]
static void Main(string[] args)
{
Updater updater = new Updater();
if (updater.PendingUpdate)
{
Application.EnableVisualStyles();
DialogResult result = MessageBox.Show("There is an
update availiable , would you want to download and install it?",
"Updater", MessageBoxButtons.YesNo);
if (result == DialogResult.Yes)
{
updater.DownloadUpdates(); // since the download
is threaded this just returns!?
}
}
else if (args[0] == "/shownot")
{
MessageBox.Show("Hotel Management Studio is up to
date");
}
//do {} //this does'nt work!?
//while (updater.Completed);
}

Thanks so much

Gideon

Jun 19 '07 #1
2 2165
On Tue, 19 Jun 2007 07:30:19 -0700, giddy <gi*******@gmail.comwrote:
[...]
Since i dont need a windows form to check if there is an update , I
dont use a form unless i have two. This , creates either one of two
problems. When i'm downloading asynchonously , the main thread exits!
Or if use a blocked download , how do i display progress!?

In the updater.DownloadUpdates() , i show a reusable ProgressForm ,
and update it in the downloadProgress changed event, but it just shows
and nothing happens and the App never closes!?
Somewhere in there, you need to wait until your progress status form
closes, and you need to close the progress status form when you're done,
as well as update it to show progress.

There are a variety of ways you could do this, but IMHO the most obvious
is to start with the basic template for a form-based application and
modify that. So, do the usual Application.Run() on the new form instance,
but in your case only if you need to do the update.

Once you have that in place, then there's question of how to interact with
your updater thread. You don't say how you've implemented it, but it
seems to me that the BackgroundWorker class would work fine in this
instance. It provides well-defined mechanisms for all of the behaviors
you're looking for. In particular, progress notifications as well as
completion notification. In the completion notification, you can use
Invoke() to call some code that closes your progress form, and the
application will exit at that point (well, it will return from
Application.Run(), and that should naturally fall out of the Main()
method, exiting the application).

Pete
Jun 19 '07 #2
HI,

Thanks so much, Application.Run()! thats all it needed!

Oh , i used the WebClient class inside the Updater class. It has a
DownfileAsync() and DownProgressChanged and DownloadCompleted events

Gideon

Jun 24 '07 #3

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

Similar topics

2
by: Bruce Vander Werf | last post by:
How can I cleanly stop a thread that is currently blocking on Socket.Receive? I don't want to use Thread.Abort, because I would like the thread method to exit cleanly, and the same code must run...
2
by: Tash Robinson | last post by:
I have been searching and can not seem to find a good example of a working UDP client that listens, but does not block while waiting for data arrival. I am trying to write a client application...
7
by: Michi Henning | last post by:
Hi, I'm using a non-blocking connect to connect to a server. Works fine -- the server gets and accepts the connection. However, once the connection is established, I cannot retrieve either the...
6
by: roger beniot | last post by:
I have a program that launches multiple threads with a ThreadStart method like the following (using System.Net.Sockets.Socket for UDP packet transfers to a server): ThreadStart pseudo code: ...
3
by: Brian Birtle | last post by:
**** A CHALLENGE TO THE GURUS - refute the statement "It's impossible to build a file upload progress meter using ASP.NET" **** First person to prove me wrong gets "All Time .NET Programming GOD"...
9
by: esakal | last post by:
Hello, I'm programming an application based on CAB infrastructure in the client side (c# .net 2005) Since my application must be sequencally, i wrote all the code in the UI thread. my...
3
by: Ritesh Raj Sarraf | last post by:
Hi, I have a small application, written in Python, that uses threads. The application uses function foo() to download files from the web. As it reads data from the web server, it runs a progress...
3
by: Bob | last post by:
Hi, I have an app that has a 3rd party phone answering control (4 of ) (interfacing with dialogic 4 line card) attached to the main form. each control raises an event when its Dialogic line...
1
by: Ryan Liu | last post by:
Hi, I have a 100 clients/ one server application, use ugly one thread pre client approach. And both side user sync I/O. I frequently see the error on server side(client side code is same, but...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.