corientdev / imagelistview

Automatically exported from code.google.com/p/imagelistview
1 stars 0 forks source link

Threads doesn't terminate after Dispose in QueuedBackgroundWorker #167

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

Create a ImageListview and dispose it. After dispose there are Threads 
leftover, because they are waiting at Monitor.Wait(lockObject); 

in QueuedBackgroundWorker.cs:

        private void Run()
        {
            while (!Stopping)
            {
                lock (lockObject)
                {
                    // Wait until we have pending work items
                    if (paused || IsWorkQueueEmpty())
                        Monitor.Wait(lockObject);
                }
             ...

Every time a create a new ImagelistView, there are more Threads leftover!

What is the expected output? What do you see instead?
After Dispose, all created Threads should be terminated.

What version of the product are you using? On what operating system?
ImageListView 11.0.0.0 and Windows 7 Profesional

Please provide any additional information below.

My Solution for this:

Dispose in QueuedBackgroundWorker.cs only call once Monitor.Pulse(lockObject);
so only the thread at the head of the waiting queue is affected!

I add only a for loop to iterate the threads and send Pulse for all threads:

for (int i = 0; i < threadCount; i++)
    Monitor.Pulse(lockObject);

Dispose: 

        protected override void Dispose(bool disposing)
        {
            base.Dispose(disposing);

            if (disposed)
                return;

            lock (lockObject)
            {
                if (!stopping)
                {
                    stopping = true;
                    ClearWorkQueue();
                    cancelledItems.Clear();

                    // PEA20140730 Pulse(lockObject) for all Threads
                    for (int i = 0; i < threadCount; i++)
                        Monitor.Pulse(lockObject);
                }
            }

            disposed = true;
        }

Original issue reported on code.google.com by andi.pen...@gmail.com on 30 Jul 2014 at 1:23