Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 534305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:35:54+00:00 2026-05-13T09:35:54+00:00

I have a console application (VB.NET). When it is started, it spawns worker threads

  • 0

I have a console application (VB.NET). When it is started, it spawns worker threads to find work in the database and do the task, then look for the next task (A workflow basically).

The problem that I have is that I have my Event Handler in the main thread that spawns the worker threads. Those workers, if they error, raise an event to a public delegate. However my main thread is not detecting these events, and I cannot figure out how to make it. My intention is to do all logging (text/database), email alerts, and restarting the worker to find another task that is not errored. (This will be expanded in the LogErrorMessage routine and such, for now I am just keeping it a simple Console.Writeline so that I can see if the method is being fired or not)

Can this be done? And if so… what am I missing?

Here is the code around what I am trying to do:

Logger Class:

Public Delegate Sub LogDelegateError(ByVal Ex As Exception)

Public Class EventLogger
    Public Event EventError As LogDelegateError

    Public Sub New()
    End Sub

    Public Sub LogError(ByVal ex As Exception)
        RaiseEvent EventError(ex)
    End Sub
End Class

Main Thread:

Private WithEvents _ErrorLogger As EventLogger

Public Sub Process()
     _ErrorLogger = New EventLogger
     AddHandler _ErrorLogger.EventError, New LogDelegateError(AddressOf LogErrorMessage)

     [Loop]
     Dim tWorker As Thread = New Thread(AddressOf oWorker.MainProcess)
     tWorker.Priority = WorkerNode.Attributes(SETTING_NAME_PRIORITY).Value
     tWorker.Start()
     [End Loop]

     [In Finally]
     RemoveHandler _ErrorLogger.EventError, New LogDelegateError(AddressOf LogErrorMessage)
End Sub

Private Sub LogErrorMessage(ByVal ex As Exception) Handles _ErrorLogger.EventError
     Console.WriteLine()
     Console.WriteLine("INTERNAL ERROR:")
     Console.WriteLine(ex.ToString())
     Console.WriteLine()
End Sub

WorkerBase:

Private _Log As New EventLogger
Public Sub MainProcess()
     Try
           [SOME WORK]
     Catch ex As Exception
           Me._Log.LogError(ex)
     End Try
End Sub

I am currently getting no errors that something is wrong, nor is the application hitting the expected handler in the main thread.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:35:55+00:00Added an answer on May 13, 2026 at 9:35 am

    I use a static event do accomplish what you want.

    Code example in C#, Sorry. Just remember to remove the event if you are done using a object (Main in the example below) otherwise it’ll cause a memory leak and it’ll never get garbage collected.

    public class WorkerClass
    {
        public static event ProgressInfoEventHandler ProgressInfo;
    
        private static void OnProgressInfo(string message)
        {
            if (ProgressInfo != null)
                ProgressInfo(new ProgressInfoEventArgs(message));
        }
    
        private void DoWork()
        {
              OnProgressInfo("Doing some work");
        }
    
    }
    

    Main or Logging thread/class:

    public class Main
    {
       public Main()
       {
            WorkerClass.ProgressInfo += 
                 new ProgressInfoEventHandler(WorkerClass_ProgressInfo);
       }
    
        void WorkerClass_ProgressInfo(ProgressInfoEventArgs e)
        {
            //LogMessage(e.Message);
        }
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 287k
  • Answers 287k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer gdb? If not, clarify your question. May 13, 2026 at 5:09 pm
  • Editorial Team
    Editorial Team added an answer You just need to configure the Django settings before you… May 13, 2026 at 5:09 pm
  • Editorial Team
    Editorial Team added an answer In C the type of a string literal is a… May 13, 2026 at 5:09 pm

Related Questions

I have a Visual Studio 2008 solution with two projects (a Word-Template project and
I am getting a Method not found: 'Boolean MyCompany.LibraryAssembly.SomeFunction(System.String)' exception/error when running a VB.NET
We're writing a .NET winform application and I'm looking for options on one of
I'm working on a vb.net console app that opens a number of spreadsheets one
I have encountered an error while debugging a VB.Net application in Visual Studio 2008.

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.