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

  • SEARCH
  • Home
  • 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 8378641
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:58:25+00:00 2026-06-09T15:58:25+00:00

I need to create a separate thread for my application to log a few

  • 0

I need to create a separate thread for my application to log a few things and it was suggested to me to use Task.

I don’t seem to have this right since I don’t fully understand task (I guess).

Here is what I have:

public static void LogException(string message, Exception ex)
{
  Action action= delegate() { logException(message, ex); };
  new Task(action);
}

public static void logException(string message, Exception ex)
{
  var stackTrace = new StackTrace();
  var origin = stackTrace.GetFrame(1).GetMethod().Name;
  var originclass = stackTrace.GetFrame(1).GetMethod().ReflectedType.Name;
  var neworigin = string.Format("{0}.{1}", originclass, origin);

  message += Environment.NewLine + Environment.NewLine + GetFullExceptionMessage(ex);

  if (string.IsNullOrEmpty(message)) message = "No message given";

  //var exceptions = GetAllErrMessages(ex);
  //message = exceptions.Aggregate(message, (current, exception) => current + Environment.NewLine + exception);

  EventLogging.LogEvent(neworigin, message, EventLogEntryType.Error, 9999);

  EmailMessage(neworigin, message, EventLogEntryType.Error);
}

What am I doing wrong? I am not getting any errors but then again, I’m not getting any log.

Thanks!

  • 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-06-09T15:58:27+00:00Added an answer on June 9, 2026 at 3:58 pm

    new Task(action); creates a new task, but it doesn’t do anything that would result in it actually be executed.

    In this case, you can probably just use:

    Task.Factory.StartNew( () => { /* code goes here */ });
    

    It’s worth mentioning that if your code is particularly short then the overhead of creating/scheduling the task might be slower than actually running it directly (this will of course depend on what that code is). Also make sure that your error logging will work properly when events are logged in a multithreaded environment. If not, you may either decide to not bother, or add explicit locking.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As an addition to my current application, I need to create a separate thread
I'm trying to create a .NET application that uses OpenGL. I need to have
I use MS SQL 2008 R2, I need create a Table with a CHECK
I have dynamically created WrapPanel (_wp) with several Borders. And I need create handler
I need to create a WP site which will have multiple subjects. Each subject
I have a Qt application with this kind of main()... int main(int argc, char
I have some GUI controls in WinForms application. For example i have log control
I'm trying to create a multithreaded opengl application with libx11 - with one separate
I'd like to create a separate thread for heavy computations in my Pylons project
I have an windows form application written in C# in which I use a

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.