logo
Tags down

shadow

How to monitor a vital worker thread


By : user3851614
Date : October 16 2020, 11:12 AM
around this issue I have a worker thread that is vital for my application. , Why don't you wrap your main thread routine like this:
code :


Share : facebook icon twitter icon

how is it possible, 3 threads are in blocked state waiting same monitor, and there is no thread owned that monitor


By : digibro
Date : March 29 2020, 07:55 AM
To fix the issue you can do At first I suspected a Lock object not being unlocked in finally. But then I had a look at two thread dumps you provided.
Indeed 3 threads are blocked on the same lock, namely it is Log4J, Category class. According to thread dump, this is the code they are all blocked on:
code :
for(Category c = this; c != null; c=c.parent) {
  synchronized(c) {  // LOCKED HERE
    if(c.aai != null) {
      writes += c.aai.appendLoopOnAppenders(event);
    }
    if(!c.additive) {
      break;
    }
  }
}
-XX:+PrintGCDetails
-XX:+PrintGCTimeStamps
-XX:+PrintHeapAtGC
-Xloggc:gc.log

How to stop a background worker thats on a new thread, how to cancel when worker has multiple functions?


By : Daniel Money
Date : March 29 2020, 07:55 AM
hop of those help? The CancelAsync() method does nothing else but set the bwAsync.CancellationPending flag to true on the worker's thread. In order for the cancellation to actually do anything, you have to verify the flag whenever you deem the process ready to be canceled, something like this:
code :
private void bwAsync_DoWork(object sender, DoWorkEventArgs e)
{
    // The sender is the BackgroundWorker object we need it to
    // report progress and check for cancellation.
    BackgroundWorker bwAsync = sender as BackgroundWorker;

    if(!bwAsync.CancellationPending)
    {
        //Criar o Backup dos ficheiros do cliente e do serviço antigo
        UpdateMessage("A criar backup dos ficheiros de Cliente");
        Program.Funcoes.DirectoryCopy(Global.OldClient, textBoxBackup.Text + "\\OrcaClientBackup", true, true);
        bwAsync.ReportProgress(10);
    }

    if(!bwAsync.CancellationPending)
    {           
        UpdateMessage("A criar backup dos ficheiros do Serviço");
        Program.Funcoes.DirectoryCopy(Global.OldService, textBoxBackup.Text + "\\OrcaServiceBackup", true, true);
        bwAsync.ReportProgress(15);
    }

    if(!bwAsync.CancellationPending)
    {
        ////A Parar e desinstalar o Serviço Actual
        UpdateMessage("A parar o Serviço existente");
        Program.Funcoes.StopService("OrcaService", 1000, true);
        bwAsync.ReportProgress(20);
    }

    if(!bwAsync.CancellationPending)
    {
        //Eliminar os ficheiros do Serviço Antigo
        UpdateMessage("A preparar os ficheiros para actualizar o cliente");
        //Program.Funcoes.DeleteAll(Global.OldService);
        bwAsync.ReportProgress(30);
    }

    if(!bwAsync.CancellationPending)
    {
        //Eliminar os ficheiros do Serviço Antigo
        //Program.Funcoes.DeleteAll(Global.OldClient);
        UpdateMessage("A preparar os ficheiros para actualizar o serviço");
        bwAsync.ReportProgress(40);
    }

    if(!bwAsync.CancellationPending)
    {
        //Copiar os Novos Ficheiros
        UpdateMessage("A actualizar o Cliente");
        Program.Funcoes.DirectoryCopy(Global.NovoCliente, Global.OldClient, true, false);
        bwAsync.ReportProgress(50);
    }

    if(!bwAsync.CancellationPending)
    {
        UpdateMessage("A actualizar o Serviço");
        Program.Funcoes.DirectoryCopy(Global.NovoServiço, Global.OldService, true, false);
        bwAsync.ReportProgress(55);
    }

    if(!bwAsync.CancellationPending)
    {
        //Fazer as alterações ao Orca.config.exe
        UpdateMessage("A configurar o Cliente");
        WriteConfigOrca(Global.OldClient);
        Program.Funcoes.UpdateCliente(Global.OldClient + @"\Orca.exe.config", Global.NovoCliente + @"\Orca.exe.config");
        bwAsync.ReportProgress(70);
    }

    if(!bwAsync.CancellationPending)
    {           
        UpdateMessage("A configurar o Serviço");
        Program.Funcoes.UpdateService(Global.OldService + @"\OrcaService.exe.config", Global.NovoServiço + @"\OrcaService.exe.config");
        //WriteConfigOrcaService(Program.OldService + "\\OrcaService.exe.config");
        bwAsync.ReportProgress(85);
    }

    if(!bwAsync.CancellationPending)
    {
        //Instalar o serviço
        UpdateMessage("A instalar o novo Serviço");
        Program.Funcoes.InstallService(Global.OldService + "\\OrcaService.exe");
        Thread.Sleep(100);
        bwAsync.ReportProgress(100);
    }
    return;
}

Background worker c# stop worker - immediately (include Thread.Sleep in DoWork)


By : Ulisses Gurgel
Date : March 29 2020, 07:55 AM
help you fix your problem I think that standard BackgroundWorker is not suitable for your case and you should do something custom that better support combination of sleep and cancellation. Following code is an idea of what you might want to do:
CancellableBackgroundWorker.cs
code :
public delegate void CancellableBackgroundJob(ICancellationProvider cancellation);

public interface ICancellationProvider
{
    bool CheckForCancel();

    void CheckForCancelAndBreak();

    void SleepWithCancel(int millis);
}


public class CancellableBackgroundWorker : Component, ICancellationProvider
{
    private readonly ManualResetEvent _canceledEvent = new ManualResetEvent(false);
    private readonly CancellableBackgroundJob _backgroundJob;

    private volatile Thread _thread;
    private volatile bool _disposed;

    public EventHandler FinishedEvent;


    public CancellableBackgroundWorker(CancellableBackgroundJob backgroundJob)
    {
        _backgroundJob = backgroundJob;
    }

    protected override void Dispose(bool disposing)
    {
      Cancel();
      _disposed = true;
    }

    private void AssertNotDisposed()
    {
        if (_disposed)
            throw new InvalidOperationException("Worker is already disposed");
    }

    public bool IsBusy
    {
        get { return (_thread != null); }
    }

    public void Start()
    {
        AssertNotDisposed();
        if (_thread != null)
            throw new InvalidOperationException("Worker is already started");
        _thread = new Thread(DoWorkWrapper);
        _thread.Start();
    }


    public void Cancel()
    {
        AssertNotDisposed();
        _canceledEvent.Set();
    }

    private void DoWorkWrapper()
    {
        _canceledEvent.Reset();
        try
        {
            _backgroundJob(this);

            Debug.WriteLine("Worker thread completed successfully");
        }
        catch (ThreadAbortException ex)
        {
            Debug.WriteLine("Worker thread was aborted");
            Thread.ResetAbort();
        }
        finally
        {
            _canceledEvent.Reset();
            _thread = null;
            EventHandler finished = FinishedEvent;
            if (finished != null)
                finished(this, EventArgs.Empty);
        }
    }


    #region ICancellationProvider

    // use explicit implementation of the interface to separate interfaces
    // I'm too lazy to create additional class

    bool ICancellationProvider.CheckForCancel()
    {
        return _canceledEvent.WaitOne(0);
    }

    void ICancellationProvider.CheckForCancelAndBreak()
    {
        if (((ICancellationProvider)this).CheckForCancel())
        {
            Debug.WriteLine("Cancel event is set, aborting the worker thread");
            _thread.Abort();
        }
    }

    void ICancellationProvider.SleepWithCancel(int millis)
    {
        if (_canceledEvent.WaitOne(millis))
        {
            Debug.WriteLine("Sleep aborted by cancel event, aborting the worker thread");
            _thread.Abort();
        }
    }

    #endregion

}
public partial class Form1 : Form
{
    private readonly CancellableBackgroundWorker _backgroundWorker;

    public Form1()
    {
        InitializeComponent();

        _backgroundWorker = new CancellableBackgroundWorker(DoBackgroundJob);
        _backgroundWorker.FinishedEvent += (s, e) => UpdateButton();

        // ensure this.components is created either by InitializeComponent or by us explicitly
        // so we can add _backgroundWorker to it for disposal
        if (this.components == null)
            this.components = new System.ComponentModel.Container();

        components.Add(_backgroundWorker);
    }

    private void UpdateButton()
    {
        // Ensure we interact with UI on the main thread
        if (InvokeRequired)
        {
            Invoke((Action)UpdateButton);
            return;
        }

        button1.Text = _backgroundWorker.IsBusy ? "Cancel" : "Start";
    }

    private void button1_Click(object sender, EventArgs e)
    {
        if (_backgroundWorker.IsBusy)
        {
            _backgroundWorker.Cancel();
        }
        else
        {
            _backgroundWorker.Start();
        }
        UpdateButton();
    }

    private void DoBackgroundJob(ICancellationProvider cancellation)
    {
        Debug.WriteLine("Do something");

        // if canceled, stop immediately
        cancellation.CheckForCancelAndBreak();

        Debug.WriteLine("Do something more");
        if (cancellation.CheckForCancel())
        {
            // you noticed cancellation but still need to finish something
            Debug.WriteLine("Do some necessary clean up");
            return;
        }

        // Sleep but cancel will stop and break
        cancellation.SleepWithCancel(10000);
        Debug.WriteLine("Last bit of work");
    }
}

How to monitor IIS worker process using Windows performance monitor


By : Shanks Adsul
Date : March 29 2020, 07:55 AM
seems to work fine As far as I know, we could add counter in the process monitor to figure out the Process identifier of the process.
You could right click the performance window and select counter.

How to call another worker from sidekiq worker and monitor its progress without pausing child worker


By : user3202447
Date : March 29 2020, 07:55 AM
This might help you What you are looking here is something similar to Sidekiq Workflow. But this is available only on Sidekiq-Pro version, which is paid.
Related Posts Related Posts :
  • How can I get back a previously created Excel ListObject?
  • What API can be used to read OAB Files?
  • In linq to entity, how to retrieve objects matching a list of conditions without looping?
  • RESTful web service in C# code
  • C#, Process.Start hide?
  • Multi resolution
  • Alternatives for Crystal Report
  • Lucene.NET, StandardAnalyzer, stopwords and thread-safety
  • How to implement CCAvenue payment gateway option
  • Silverlight and WCF: NotFound error!
  • C# How can I get a list of country codes?
  • Intellisense - Javascript in a string
  • How to change the opacity value of a 3D object
  • Assembly.ReflectionOnlyLoadFrom not working
  • C# Audio - How to time stretch (different tempo, same pitch)
  • Getting certain lines of text c#
  • Can we display Hyperlink from Javascript alert on ASP.NET Page?
  • Can you see programmatically how much amperage a USB device is requesting in windows?
  • What is a way to do a Generic Repository with Entity Framework 4.0 where I have function imports?
  • C# How to determine if a date is within 180 days of now
  • Programmatically hiding properties in a PropertyGrid
  • How do I get a list of fields returned by an OdbcDataReader?
  • ASP.Net Creating Server Side Posting to external website with redirect
  • Adding a tool bar to a web page
  • Convert Audio file into MP3 format using C#
  • Check if a windows service is running?
  • Assembly re-direction in .NET
  • Parse and filter javascript array
  • How to handle a generic dictionary whose types are unknown and don't matter?
  • Distribute images with C# Setup project
  • Is there a way to publish rdl reports programmatically with C#?
  • How to call base.base.method()?
  • How to install Emgu CV wrapper?
  • Interview question - c#
  • .NET Remoting client config creates local object, not remote
  • Is there a possibility to differ virtual printer from physical one?
  • Print barcode which has high scan rate
  • Query string value having "&"
  • Which is best for perfomance?
  • Can we make overloaded controller method in ASP .NET MVC
  • Nested loop in StringTemplate
  • How to get SSID and RSSI for Win7 using C#
  • Send messages to applications on the network (.Net)
  • Detect and prevent/delay windows mobile power off
  • How X509 Certificate renewal does not impact the code?
  • Silverlight: How to make my custom control act like a button
  • C# basic Dictionary Ordering Just need to clear an error
  • Common c# idioms including coalesce ?? operator
  • Why Does Thread.CurrentThread.CurrentCulture Change between Page Rendering and HttpModule.PostRequestHandlerExecute?
  • COM Exception 0x8004005
  • How do I show a message box from inside a class in a class library?
  • LINQ Distinct Query
  • Issue with number guessing game c#
  • Usage of a using statement
  • Building a forms system using DDD
  • How can I programmatically tell in C# if an unmanaged lib is x86 or x64?
  • How do I get an Excel range using row and column numbers in VSTO / C#?
  • .NET 4.0 Memory Mapped Files Performance
  • db4o Indexing problem - Not Working? Poor performance?
  • Realtime Console Output Redirection using Process
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org