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 8010017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T18:36:44+00:00 2026-06-04T18:36:44+00:00

We are dealing with processing and uploading of large files in windows service (.net

  • 0

We are dealing with processing and uploading of large files in windows service (.net 4.0). Process and upoload steps can take minutes to complete. Admin has the ability to mark job as cancelled, directly in database but to clear in memory queue it requires service restart. Goal is to abandon that job and pick next job in queue without service restart. Here’s what I want to do:

In main entry point, start two tasks:

Task processTask = Task.Factory.StartNew(ProcessJob);

Task monitorTask = Task.Factory.StartNew(MonitorDB);

ProcessJob would call multiple long running steps like ProcessFile, UploadFile. We are checking for job status between the steps but job may be stuck in one of these long running steps.

If monitorTask detects job status change in DB, it should communicate that to main thread (through exception or message), so that main thread can quit, removing itself from the processing queue and allow next job in queue to start. Without Wait cannot get to exception but cannot wait because need to run these tasks in parallel.
At this time we are not concerned with the fact that some synch step in ProcessJob may still be going on and it may eventually complete. We would handle that in code.

So far in all of my applications, I have used Task.ContinueWith for success and failure, but never had to communicate back to 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-06-04T18:36:46+00:00Added an answer on June 4, 2026 at 6:36 pm

    You could communicate between the monitor thread and the main thread through a BlockingCollection<T>.

    Here’s a simple example I wrote.

    BlockingCollection<string> queue =
        new BlockingCollection<string>();
    
    // monitor thread.
    Task.Factory.StartNew(() =>
    {
        while (true)
        {
            Thread.Sleep(1000);
            queue.Add("event occured.");
        }
    });
    
    // main thread.
    while (true)
    {
        // blocks when no messages are in queue.
        string message = queue.Take();
    
        // kill process thread here.
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm dealing with a large code base that uses the following construct throughout class
I'm playing around with Processing to see how everything works, but when dealing with
When dealing with image processing and computer vision these two terms come up perennially
I'm dealing with a hardware resource that can only handle 1 command at a
I'm dealing with large data, so finding a good way for reading data is
I am currently dealing with log files with sizes approx. 5gb. I'm quite new
I was once working on a Java application dealing with unicode processing - and
I am dealing with a folder hierarchy like the following: c:/users/rox/halogen/iodine/(some .txt files) c:/users/rox/halogen/chlorine/(some
I need to built a thread/process that is always running, and can be queried
Dealing with Java - which the option you prefer in the most cases -

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.