none
VB.NET - How do I use Doevents() in Class Library

    Question

  • Using VB.NET 2005 - Beta 2,

    I've created a Windows Form Application with a single form and several new Classes and now I am trying to separate them and make a .dll out of the custom classes.

    I created a new "Class Module" project and used "Add Existing Item" to select each of the custom class.vb files.

    Some of the methods attached to my custom classes take a while to run and so I had coded them interspersed with "windows.form.application.doevents()" statements.

    Now that there is no form in my new project, these lines are generating errors that "Application" is not a member of "Forms".

    So my question is:
    How can I add a 'Doevents()' to methods in my class library?

    Thanks in advance...

    Monday, September 05, 2005 5:47 PM

Answers

  • This is one way of doing it, but it is not really the best way.

    You are better off using threads to do it (and sleeping the thread to save CPU for long running tasks).

    E.g.


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim myThread As New System.Threading.Thread(AddressOf myLongTask)
        myThread.Start()

       // Do something else, thread will start in its own sweet time
    End Sub

    Private Sub myLongTask()
        Dim TaskFinished As Boolean
        Do
            System.Threading.Thread.CurrentThread.Sleep(0)
            // Do lots of stuff
        Loop Until TaskFinished = True
    End Sub

     


    And threading is a whole new world full of stuff that needs to be learnt... Smile
    Tuesday, September 06, 2005 4:18 AM

All replies

  • You need to add a reference to System.Windows.Forms.dll.
    Monday, September 05, 2005 6:25 PM
    Moderator
  • This is one way of doing it, but it is not really the best way.

    You are better off using threads to do it (and sleeping the thread to save CPU for long running tasks).

    E.g.


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim myThread As New System.Threading.Thread(AddressOf myLongTask)
        myThread.Start()

       // Do something else, thread will start in its own sweet time
    End Sub

    Private Sub myLongTask()
        Dim TaskFinished As Boolean
        Do
            System.Threading.Thread.CurrentThread.Sleep(0)
            // Do lots of stuff
        Loop Until TaskFinished = True
    End Sub

     


    And threading is a whole new world full of stuff that needs to be learnt... Smile
    Tuesday, September 06, 2005 4:18 AM
  • I'm using a lot the instruction Thread now on Framework 1.1. Very simple to use and you can get more than a single task running. Pls read tha manual written by Francesco Balena (Microsoft press) in order to get more informations
    Tuesday, September 06, 2005 6:43 AM