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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:49:47+00:00 2026-06-06T16:49:47+00:00

Calling the WriteObject Method from a background thread is not possible! Is there a

  • 0

Calling the WriteObject Method from a background thread is not possible!

Is there a possibility, to invoke/dispatch this method in the main thread of the powershell (like in WPF)?

Code sample:

protected override void ProcessRecord()
{
    base.ProcessRecord();
    ...
    Service.StartReading(filter, list => { WriteObject(list, true); } );
}

EDIT:
The error, which occured after calling the WriteObject method from the thread

Any solution, workaround or quick fix?

thx,
Mathias

  • 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-06T16:49:49+00:00Added an answer on June 6, 2026 at 4:49 pm

    I found a solution, which solves my problem.

    1. created a ConcurrentQueue

      ConcurrentQueue<LogEntryInfoBase> logEntryQueue = 
              new ConcurrentQueue<LogEntryInfoBase>();
      
    2. start a background thread to enqueue items to the ConcurrentQueue

      Task.Factory.StartNew(() => Service.StartReading(
              filter, EnqueueLogEntryInfoBases));
      
    3. meanwhile, try to dequeue from this queue in the main thread

      for ( ; ; )
      {
          LogEntryInfoBase logEntry = null;
          logEntryQueue.TryDequeue(out logEntry);
          if (logEntry != null)
          {
              WriteObject(logEntry);
          }
          Thread.Sleep(100);
      }
      

    From my point of view, this solution/fix is ugly, but it works for my current issue.

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

Sidebar

Related Questions

From my main thread I call a selector using [self performSelectorInBackground:@selector(startTask) withObject:nil]; This is
I am calling a method from two threads and thought I try this: -
i need to know is it possible to call json webservices from background, when
I had this method that I was calling and everything was fine: DataHandler: .h:
What is the real effect of calling performSelectorInBackground:... from a method that is running
I have an application in which I am repetitively calling a method in background.
Calling Html.RenderPartial(~/Views/Payments/MyControl.ascx); from a view works if MyControl.ascx is a control that directly inherits
Calling the ajax called URL works well without ajax eg. http://localhost/ci/controller/method/param_value . But using
//calling class import javax.swing.JFrame; class jcheckkbox { public static void main(String args[]) { jRadio
Calling getActionBar returns null . This has been frequently reported so I've made sure

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.