Hi,
In myVB.Net windows form app I start the appliation with a
Public Sub Main()
inside a Module. In the Main() method I need to do a whole bunch of long running stuff before loading up my Windows form. So what I wanted to do is to set the cursor to hourclass while the user is waitting for the form to load. But the problem is that no matter what I tried, the cursor won't change for me.
I tried to have Cursor.Current = Cursors.WaitCursor in several different places in Main(). I also tried calling Application.DoEvent() prior and after setting the cursor...but none of those made differences.
Can someone tell me what I am missing here?
Thanks
Feng |
| Feng26 Monday, November 10, 2008 11:02 PM |
No, that's not possible. Everybody uses a splash screen to do this. VB.NET has built-in support for them.
|
| nobugz Wednesday, November 12, 2008 5:19 PM |
Post some of your code for a better answer. You force us to guess at what you are seeing and doing.
Consider this, what type of objects is that property associated with? If you are displaying a form, then which property controls the Cursor that is dispalyed? Think it through.
Rudedog =|^D
|
| Rudedog2 Monday, November 10, 2008 11:33 PM |
Hi Rudedog2, thanks for your response!
As I said in my last email, my app starts with a Sub Main(), not a form, from within a Module, not a class. So I am not sure if I have any Control objects to display the cursor on. I thought Cursor.Current works at the Application level and doesn't need a Control object and that's why I am using it instead of Me.Cursor =...
The real code is long and complicated, but here is simplified section that I think relavent:
Imports System.Reflection
Imports System.Net
Imports System.IO
Module Launcher
Public Sub Main()
Cursor.Current = Cursors.WaitCursor
Try
' Some long running logic here...and this is where I want to see the
...
LoadForm() ' Here, after the long running process finishes, display the form
...
Thanks again!
Feng |
| Feng26 Tuesday, November 11, 2008 2:58 PM |
This seem to work for me with a blank form....
Code Snippet
Public Class Form1
Private Sub Form1_Shown(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Shown
MainLauncher()
End Sub
End Class
...and using this code to simulate your module.
Code Snippet
Imports System.Reflection
Imports System.Net
Imports System.IO
Imports System.Threading
Module Launcher
Public Sub MainLauncher()
Cursor.Current = Cursors.WaitCursor
Try
Thread.Sleep(5000)
Catch ex As Exception
End Try
Cursor.Current = Cursors.Default
End Sub
End Module
The form first appeared with the hourglass for 5 seconds, then reverted to the default cursor.
Rudedog =|^D
|
| Rudedog2 Tuesday, November 11, 2008 5:11 PM |
|
| nobugz Tuesday, November 11, 2008 6:43 PM |
Rudedog,
Thanks again for your response and code. Maybe I didn't describe the issue clear enough, so let me try it again here.
What I have is a program thatSTARTSWITHA Sub Main() in a module, NOT a form. The Main() function will, after finishing some long running tasks, eventually display the form. Bellow is some sample code that's more similar to what I do, and it didn't work either. So whatever I am missing in my real program, I must have it here, too.
Imports System.Reflection
Imports System.Net
Imports System.IO
Imports System.Threading
Public Module Module1
Public Sub Main()
Cursor.Current = Cursors.WaitCursor
Thread.Sleep(5000)
Dim oFrm As Form1 = New Form1
oFrm.Show()
End Sub
End Module
Any thoughts?
Thanks
Lifeng |
| Feng26 Tuesday, November 11, 2008 8:34 PM |
Do you have a form being displayed during the "perform tasks timeout" until your Form1 is displayed? What I did would work with a form that displayed until all of the tasks are completed. It appears you are postponing display of your initial form for your application. The cursor that you see until your initial form displays is presented by the OS, not your app.
Rudedog =P^D |
| Rudedog2 Wednesday, November 12, 2008 1:19 PM |
In other words, there is no way for a client side program to change cursor unless this program is displaying a form? That doesn't sound right to me. What is the difference between Cursor.Current = Cursors.WaitCursor and Me.Cursor = Cursors.WaitCursor then. What is Cursor.Current for?
Thanks again.
Feng |
| Feng26 Wednesday, November 12, 2008 3:11 PM |
| Feng26 wrote: |
|
In other words, there is no way for a client side program to change cursor unless this program is displaying a form? That doesn't sound right to me. What is the difference between Cursor.Current = Cursors.WaitCursor and Me.Cursor = Cursors.WaitCursor then. What is Cursor.Current for?
Thanks again.
Feng
| |
That property is for YOUR application. It is not for controlling the cursor used by other applications or the OS. That would not be fair now would it? What if somebody came along and changed the cursor in your carefully crafted application?
Rudedog =P^D |
| Rudedog2 Wednesday, November 12, 2008 3:22 PM |
Set your form's UseWaitCursor property to True.
|
| nobugz Wednesday, November 12, 2008 3:27 PM |
| nobugz wrote: |
Set your form's UseWaitCursor property to True.
| |
...and I think nobugz means to get rid of all of that other stuff, too. Never looked at that one before.
=P^D |
| Rudedog2 Wednesday, November 12, 2008 4:21 PM |
Thanks nobugz. Now I am wondering maybe what I want to do is simplly not do-able. Because it seems that nobodyunderstand what I am tring to do here.
For me though, it is a pretty simple business requirement: Our user clicks on a icon on the desktop to start the app. Before displaying the first form, the app needs to run some lengthy processes. Meanwhile, the user will be sitting there wondering what's going on. Why don't I display a form and run the process at the same time? Because the result of the process will decide what form (or any form at all) will display. So what I want to do is simply displaying an hourclass as cursor during the delay, when no form is displaying on the screen,to let the user know that something is in process. I know I can use a message box or someting like that, in stead of cursor, to inform user. But I still prefer to just have a simple hourclass if it is possible.
Does that make sense? Or am I totally wrong and shouldn't do this?
Thanks
Lifeng |
| Feng26 Wednesday, November 12, 2008 5:15 PM |
No, that's not possible. Everybody uses a splash screen to do this. VB.NET has built-in support for them.
|
| nobugz Wednesday, November 12, 2008 5:19 PM |
| Feng26 wrote: |
| Thanks nobugz. Now I am wondering maybe what I want to do is simplly not do-able. Because it seems that nobodyunderstand what I am tring to do here.
For me though, it is a pretty simple business requirement: Our user clicks on a icon on the desktop to start the app. Before displaying the first form, the app need to run some lengthy processes. Meanwhile, the user will be sitting there wondering what's going on. Why don't I display a form and run the process at the same time? Because the result of the process will decide what form (or any form at all) will display. So what I want to do is simply displaying an hourclass as cursor during the delay to let the user know that something is in process. I know I can use a message box or someting like that, in stead of cursor, to inform user. But I still prefer to just have a simple hourclass if it is possible.
Does that make sense? Or am I totolly wrong and shouldn't do this?
Thanks
Lifeng
| |
Sure, most anything is possible. The user sees an hourglass and waits. But how would the user know the application has started propertly, and not that their PC has gone awry? Present a form with the hourglass to let them know everything is proceeding according to plan.
Rudedog |
| Rudedog2 Wednesday, November 12, 2008 5:21 PM |
OK, Rudedog, I will take your advise and display a message form. Our product people think it's a bit over-kill but they are also OK with this workaround.
But I am still unsure if I am doing this is mostly because it can't be done without having a form in display...
Thanks for all your help!
Feng |
| Feng26 Wednesday, November 12, 2008 5:37 PM |
| Feng26 wrote: |
|
OK, Rudedog, I will take your advise and display a message form. Our product people think it's a bit over-kill but they are also OK with this workaround.
But I am still unsure if I am doing this is mostly because it can't be done without having a form in display...
Thanks for all your help!
Feng
| |
I do see a lot of applications that do present a hourglass until the application opens up. But, I have always attributed that behavior to the JIT Compiler doing its thing until it is finished.
Glad to have helped. =|^D |
| Rudedog2 Wednesday, November 12, 2008 5:44 PM |
Feng26
I know it's been nearly a year since you wrote this, but I totally understand the dilemma you had. I am having the same issue. Our VB.NET .exe is, essentially,a module that executes code to produce a Crystal report. It is called fromour own non-vb.net software app. I want to display the wait cursor once our non-vb.net app calls our vb.net exe and continue to display the wait cursor until it has finished executing the vb.net code.
I cannot get this to work. How did you resolve? Did you end upadding a form?
Thanks |
| N11689 Monday, September 14, 2009 2:30 PM |
As has been mentioned, you have to add a form. What if you wanted to access another application while waiting for yours to produce the report? You wouldn't be able to do anything else on your computer because your cursor would be an hourglass. That's why you need to add some kind of form telling the user what is happening, and you can use the wait cursor on that form. |
| ScottyDoesKnow Monday, September 14, 2009 3:56 PM |