C
Cool Guy
In the following code, is it possible that foo be garbage collected (and
therefore foo_Finished() never gets entered? I'd imagine so, because there
are no references to foo after Main exits. However, I can't make this
happen even with calls to GC.Collect().
using System;
using System.Threading;
delegate void ParameterlessDelegate();
class Test
{
static void Main()
{
Foo foo = new Foo();
foo.Finished += new ParameterlessDelegate(foo_Finished);
foo.Start();
}
static void foo_Finished()
{
Console.WriteLine("Finished.");
}
}
class Foo
{
public void Start()
{
new Thread(new ThreadStart(ThreadJob)).Start();
}
void ThreadJob()
{
Console.WriteLine("Working...");
Thread.Sleep(2000);
Finished();
}
public event ParameterlessDelegate Finished;
}
therefore foo_Finished() never gets entered? I'd imagine so, because there
are no references to foo after Main exits. However, I can't make this
happen even with calls to GC.Collect().
using System;
using System.Threading;
delegate void ParameterlessDelegate();
class Test
{
static void Main()
{
Foo foo = new Foo();
foo.Finished += new ParameterlessDelegate(foo_Finished);
foo.Start();
}
static void foo_Finished()
{
Console.WriteLine("Finished.");
}
}
class Foo
{
public void Start()
{
new Thread(new ThreadStart(ThreadJob)).Start();
}
void ThreadJob()
{
Console.WriteLine("Working...");
Thread.Sleep(2000);
Finished();
}
public event ParameterlessDelegate Finished;
}