?
Solved

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

Posted on 2006-11-02
9
Medium Priority
?
162 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 86

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 86

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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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
 
LVL 86

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 86

Accepted Solution

by:
Mike Tomlinson earned 2000 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 86

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…
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…
Suggested Courses

765 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