Search code examples
c#multithreadinggarbage-collectiondispose

How can I run GC in main thread - C#?


I have:

public static Thread MainThread
{
    get { return Thread.CurrentThread; }
}

in my "main" class

I want to do following in other class:

~Class()
{
    Program.MainThread.Start(this.Dispose(false));
}

How can I run method in some thread? How can I run GC in main thread?


Solution

  • How can I run CG in main thread?

    GC always runs in it's own threads.

    How can I run method in some thread?

    You can not unless the other thread has an API entry point waiting for things to process (like the UI has where you can invoke into the message pump).