Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5981207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:54:42+00:00 2026-05-22T21:54:42+00:00

If I have minimum 2 classes. One class creates the Bitmap and the other

  • 0

If I have minimum 2 classes. One class creates the Bitmap and the other draws the bitmap on UI form. I want to ask you if there is any variable I can transport from UIClass to the GeneratorClass except the whole Form or any control. I prefer to transport the “Thread” as property from UIClass to GeneratorClass and in GeneratorClass I can create the image there by invoking in UIThread.

I know:

Control.Invoke(Delegate, Parameters)

Or in WPF

Control.Dispatcher(Delegate, Parameters)

I also know

System.Threading.Thread(ThreadStart)

I prefer to only have a “Thread-Variable” to work with to start Invoking or to use Dispatcher to stay on WPF and WinForms and GeneratorClass with same Thread.

Thanks for your ideas (preferred in VB.Net)

* My working answer *

use the shared Threading.SynchronizationContext.Current to receive the current UI Thread. Then use
GuiThread.Send(AddressOf MyMethode, MyParameters) to work in UI thread.

 Private Sub CreateTestImage()
        'This methode is needed to work in Ui Thread
        Dim SyncContext As Threading.SynchronizationContext = Threading.SynchronizationContext.Current 'Read current UI Thread and store it to variable
        If Me._UseMultiThreading = True Then
            'call methode WITH multthreading
            Dim ThS As New Threading.ParameterizedThreadStart(AddressOf CreateTestImageAsync)
            Dim Th As New Threading.Thread(ThS)
            Th.SetApartmentState(Threading.ApartmentState.STA)
            Th.Start(SyncContext)
        Else
            'call methode WITHOUT multthreading
            Call CreateTestImageAsync(SyncContext)
        End If
    End Sub

Methode in thread:

Private Sub CreateTestImageAsync(ByVal obj As Object)
    'Callback is only supporting As Object. 
    'Cast it back the the SynchronizationContext 
    Dim GuiThread As Threading.SynchronizationContext = CType(obj, Threading.SynchronizationContext)

    'Do some stuff

    GuiThread.Send(AddressOf ImageCreated, ImgInfo) 'Call methode in UI thread
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:54:42+00:00Added an answer on May 22, 2026 at 9:54 pm

    You would pass the current SynchronizationContext to the thread.
    in your thread it would look something like this:

    void ThreadMethod(object parameter)
    {
        var context = (SynchronizationContext)parameter;
    
        context.Send((s) => TheMethodYouWantToRunOnTheUiThread(), null);
    }
    

    You would start your thread like this:

    var newThread = new Thread(ThreadMethod);
    newThread.Start(SynchronizationContext.Current);
    

    It is in C#, but I think you can translate it.

    BTW: This is the very same mechanism used by the BackgroundWorker class to marshal the events ProgressChanged and Completed to the UI thread. See here for more info on this topic

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a habit of keeping my variable usage to a bare minimum. So
Have you ever seen any of there error messages? -- SQL Server 2000 Could
I have a class ImageA, and a class ImageB. The both classes represents an
I'm currently making a Drag-and-Drop javascript engine. I want to make one class (
All, Is there a way to have a minimum time to keep a stream
How can I find what databases I have a minimum of read access to
I would like to keep the overhead at a minimum. Right now I have:
How do you set up NAnt with only the bare minimum binaries? I have
Have you guys had any experiences (positive or negative) by placing your source code/solution
Let's say you want to diagram a Map class (the mathematical kind, not the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.