Aks
Aks

Reputation: 5236

C# BackgroundWorker ReportProgress Int32?

I want to display progress from a BackgroundWorker to a ProgressBar in the UI. What I dont understand is why the BackgroundWorker's ReportProgress function takes an Int32 when the ProgressBar can take a double value for progress. My process is very intricate and I need to make decimal progress updates. It doesnt help if I have to keep adjusting everything to the nearest integer. Can anyone suggest someway i can work around this?

Upvotes: 3

Views: 1215

Answers (2)

grimmig
grimmig

Reputation: 1421

ReportProgress also has a second variant where it takes an object as an additional parameter:

public void ReportProgress(
    int percentProgress,
    Object userState
)

Simply pass your double as the userState object.

On a side note: Are you sure your Progress bar has so many pixels that you need a double to enumerate them all?

Upvotes: 2

Simon Mourier
Simon Mourier

Reputation: 138841

The ProgressChangedEventArgs Class can take an optional UserState value. You can pass anything you want to this (including for example a double value). Set it with the ReportProgress method

Upvotes: 4

Related Questions