Solved

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

Posted on 2006-11-02
9
151 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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

760 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

18 Experts available now in Live!

Get 1:1 Help Now