Windows Forms ProgressBar: Easiest way to start/stop marquee?
Use a progress bar with the style set to Marquee
. This represents an indeterminate progress bar.
myProgressBar.Style = ProgressBarStyle.Marquee;
You can also use the MarqueeAnimationSpeed
property to set how long it will take the little block of color to animate across your progress bar.
C# - ProgressBar with Marquee style
I've checked several posts about BackgroundWorker, but in my case the
operation doesn't report progress, that's why I need a Marquee bar.
You can use the BackgroundWorker, just don't use the "progress" portion of it. These two things are not mutually exclusive...
Example:
private void button1_Click(object sender, EventArgs e)
{
button1.Enabled = false;
progressBar1.Style = ProgressBarStyle.Marquee;
progressBar1.MarqueeAnimationSpeed = 50;
BackgroundWorker bw = new BackgroundWorker();
bw.DoWork += bw_DoWork;
bw.RunWorkerCompleted += bw_RunWorkerCompleted;
bw.RunWorkerAsync();
}
void bw_DoWork(object sender, DoWorkEventArgs e)
{
// INSERT TIME CONSUMING OPERATIONS HERE
// THAT DON'T REPORT PROGRESS
Thread.Sleep(10000);
}
void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
progressBar1.MarqueeAnimationSpeed = 0;
progressBar1.Style = ProgressBarStyle.Blocks;
progressBar1.Value = progressBar1.Minimum;
button1.Enabled = true;
MessageBox.Show("Done!");
}
how to stop a progress bar control from well progressing
Set the Style
property to a value other than Marquee
:
progressBar.Style = ProgressBarStyle.Marquee; // marquee animation starts
progressBar.Style = ProgressBarStyle.Continuous; // marquee animation stops
Winform marquee progress bar freezes
As stated in my comment, the use of Wait-Job
will block your current thread hence the form will also become unresponsive. Instead, you can use a loop while
or do
, to wait for your job and call Application.DoEvents
Method as a workaround:
$button.Add_Click({
$ProgressBar1.Show()
$this.Enabled = $false
$job = Start-Job -ScriptBlock {
Get-ChildItem -File -Recurse $HOME -ErrorAction SilentlyContinue
}
while($job.State -eq 'Running') {
[System.Windows.Forms.Application]::DoEvents()
}
$job | Receive-Job -AutoRemoveJob -Wait | Out-Host
$ProgressBar1.Hide()
$this.Enabled = $true
})
How to run a progress bar for entire duration of a button (C# Windows Form)
Mark your button1 Click() handler with async
, then use await
and Task.Run
:
private async void button1_Click(object sender, EventArgs e)
{
// START PROGRESS BAR MOVEMENT:
button1.Enabled = false;
pb.Style = ProgressBarStyle.Marquee;
pb.Show();
// DO THE WORK ON A DIFFERENT THREAD:
await (Task.Run(() =>
{
System.Threading.Thread.Sleep(5000); // simulated work (remove this and uncomment the two lines below)
//LoadDatabase.Groups();
//ProcessResults.GroupOne();
}));
// END PROGRESS BAR MOVEMENT:
pb.Hide();
button1.Enabled = true;
}
How to start a progressbar at a certain position in a stop/play animation? [Xamarin forms]
try something like this to set the initial value of the animation
var animation = new Animation (v => progressBar.Progress = v, 0.3, 1);
animation.Commit (this, "SimpleAnimation", 16, 2000, Easing.Linear, (v, c) => image.Scale = 1, () => false);
to cancel
this.AbortAnimation ("SimpleAnimation");
How can I make an endless progressbar in WinForms?
System.Windows.Forms.ProgressBar has a property called Style
. Setting Style
to Marquee
will achieve the effect your looking for.
EDIT: Divo points out the Marquee Style is only available on
Windows XP Home Edition, Windows XP Professional x64 Edition, Windows Server 2003
The comments provide even more information indicating that this appears to work everywhere as long as you're using .NET 2.0 or higher.
Related Topics
Razor: Declarative HTML Helpers
C# - Capturing the Mouse Cursor Image
Send Smtp Email Using System.Net.Mail via Exchange Online (Office 365)
How to Make a Call to My Wcf Service Asynchronous
Entity Framework/Sql2008 - How to Automatically Update Lastmodified Fields for Entities
How to Ignore Null Values for All Source Members During Mapping in Automapper 6
Is Endinvoke() Optional, Sort-Of Optional, or Definitely Not Optional
ASP.NET MVC 4 Multiple Post via Different Forms
Should You Declare Methods Using Overloads or Optional Parameters in C# 4.0
How to Serialize an Exception Object in C#
What Is the Fastest Way to Combine Two Xml Files into One
Newtonsoft Add JSONignore at Runtime
Creating Delegates Manually VS Using Action/Func Delegates
How to Implement a Progress Bar in C#
How to Convert an Iso8601 Timespan to a C# Timespan
How to Use Httpclient to Send Content in Body of Get Request