2 Replies - 95 Views - Last Post: 08 February 2012 - 06:43 AM Rate Topic: -----

Topic Sponsor:

#1 papalocke  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 03-February 12

Passing args to and understanding Backgroundworker

Posted 08 February 2012 - 06:29 AM

Hey guys, Solofrog here and im having trouble understanding something really quick and would like if someone could just clear it up really quick and maybe give me a visual example.

Private Sub BackgroundWorker1_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork

        Dim wmi As ManagementClass
        Dim inParams, outParams As ManagementBaseObject
        Dim obj As ManagementObject
        Dim Result As String
        wmi = New ManagementClass("\\" & strComputer & "\root\cimv2:Win32_OperatingSystem")
        For Each obj In wmi.GetInstances()
            ' Get an input parameters object for this method
            inParams = obj.GetMethodParameters("Win32Shutdown")

            ' fill 'em in
            inParams("Flags") = actionOption + 4
            inParams("Reserved") = 0

            ' do it!
            outParams = obj.InvokeMethod("Win32Shutdown", inParams, Nothing)
            Result = Convert.ToInt32(outParams("returnValue"))
        Next

    End Sub



As you see i this is what i have setup so far as far as the backgroundworker goes.... this is just a segment of code but i didnt feel the rest was needed. ANYWAYS, when i found out about the backgroundworker and that it might solve another problem ive been having unrelatedly, I copied a Sub that i had into the backgroundwoker. The Sub i copied had 2 other agruements passed through it, a String and an Int (in the code they are strComputer, and actionOption.

I want this in the background mainly because when i go to shut down all the computers at night it will work a while, freeze the whole program while doing this and then unknowingly freeze and stop randomly through it.

Any ideas, or help will be much appreciated, thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: Passing args to and understanding Backgroundworker

#2 m_wylie85  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 65
  • View blog
  • Posts: 661
  • Joined: 15-October 10

Re: Passing args to and understanding Backgroundworker

Posted 08 February 2012 - 06:37 AM

Hi Papa you could check out Adam's tutorial

http://www.dreaminco...kground-worker/

This should help you understand background workers
Was This Post Helpful? 0
  • +
  • -

#3 papalocke  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 03-February 12

Re: Passing args to and understanding Backgroundworker

Posted 08 February 2012 - 06:43 AM

Ok i messed around with it more and am i just stupid? I had all the main code under a button press and going into that Sub, instead of putting the sub code in the worker i should just put the button code in the worker and call the worker when the button presses..... right? makes sense

Also thank you very much Wylie
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1