Solved

Thread with an Icon.Save command  cannot be ended by Scheduled Task "End Task" option.

Posted on 2006-11-02
9
152 Views
Last Modified: 2010-04-30
I have a VB.Net console application that issues an Icon.Save command to a memory stream. I defined a Scheduled task to process it. I issue start and stop commands from the Scheduled Tasks menu.

When I issue the end task, the status on the Scheduled Task display goes from "Running" to blank. However, from the Task Manager display the process is still there. The main task is still running; I put an Event log display in to verify it.

The problem occurs on 2 XP/Pro SP 2 (current) machines. A W/2000 server machine does not have the problem. The code was compiled with VS 2003. Here is a sample program to illustrate:

Imports System.Threading
Imports System.Drawing
Imports System.IO

Module Module1

    Dim Thr1 As Thread
    Dim stream As New MemoryStream
    Dim tIcon As New Icon("C:\Mike\OffStor\Icons\BackupSet\BackupSet.ico")

    Sub Main()

        Thr1 = New Thread(AddressOf Thr1Sub)
        Thr1.IsBackground = False
        Thr1.Start()

        While True
            Thread.Sleep(5000)
        End While

    End Sub

    Private Sub Thr1Sub()

        tIcon.Save(Stream)

    End Sub

 
End Module
0
Comment
Question by:MikeBroderick
  • 5
  • 4
9 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17859042
What exactly are you trying to achieve with this code?

This part:

        While True
            Thread.Sleep(5000)
        End While

causes an infinite loop and an unrepsonsive app due to the Sleep() call.

Give us the big picture...
0
 

Author Comment

by:MikeBroderick
ID: 17859195
This is huge simplification of the application. The main task is a tcp listener task that processes incoming commands. The sub task does lots of stuff then ends. it receives the name of a file to process, retrieves the associated icon for that file, then convert the icon into a base 64 string for further processing. I removed all of that because none of it causes the problem.
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17859273
Well, the only thing that pops out is the IsBackground() setting of False:

    Thr1.IsBackground = False

From:
http://msdn2.microsoft.com/en-gb/library/system.threading.thread.isbackground.aspx

    "A thread is either a background thread or a foreground thread. Background threads are identical to foreground threads, except that background threads do not prevent a process from terminating. Once all foreground threads belonging to a process have terminated, the common language runtime ends the process. Any remaining background threads are stopped and do not complete."

Since it is NOT a background thread the app is waiting for it to complete before ending...
0
 

Author Comment

by:MikeBroderick
ID: 17859332
I'm sorry. Just for grins I changed that to False to see if it would work (grasping at straws) and forgot to change it back. True fails also.

I think the sub task is ending OK, it executes to end. If I comment out the icon.save command, I dont have the problem.

Is there any (efficient) way to search Microsoft for known problems, or to report the problem without paying 99 dollars for a support charge?
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17859413
Are you actually using some kind of loop to keep your main task alive?

        While True
            Thread.Sleep(5000)
        End While

Look at inheriting from the ApplicationContext() class instead:
http://msdn2.microsoft.com/en-US/library/system.windows.forms.applicationcontext.aspx

A simple example:

Module Module1

    Public Sub Main()
        Application.Run(New MyContext)
    End Sub

    Public Class MyContext
        Inherits ApplicationContext

        Private Thr1 As Thread
        Private stream As New MemoryStream
        Private tIcon As New Icon("C:\Mike\OffStor\Icons\BackupSet\BackupSet.ico")

        Public Sub New()
            Thr1 = New Thread(AddressOf Thr1Sub)
            Thr1.IsBackground = True
            Thr1.Start()
        End Sub

        Private Sub Thr1Sub()
            tIcon.Save(Stream)
        End Sub

    End Class

End Module

0
 

Author Comment

by:MikeBroderick
ID: 17859588
Just gave it a shot. Same error.

0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 17859608
I'm outa suggestions then...  =(

The problem lies in the Icon.Save() method.
0
 

Author Comment

by:MikeBroderick
ID: 17859638
Thats what I came to conclude. I dont have to fix this (not enough to spend 100 dollars to ask Microsoft). Do you know of any way to check with Microsoft on known bugs with XP (it works on 2000)?
0
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 17859706
I'm not sure how to report bugs.

I just do searches on the msdn site:
http://msdn2.microsoft.com/en-us/default.aspx
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now