L
leonardo.bassi18
Guest
Hello everyone,
I am developing a sample wpf application with 2 progess bar, which start independently when the correspond button been clicked.
I achieve this result using c# thread, but now i run into some problems like many c# instructions aren't implemented on vb.net.
Surfing on the internet i found the backgroundworkers solution, but in my view this method is heavy and not good for the thing which i want to do.
Below i attach the working c# and xaml code, and my question is: If this is possible to obtain this in vb.net
C# code
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private async void Button_prog1_Click(object sender, RoutedEventArgs e)
{
button_prog1.IsEnabled = false;
var progress = new Progress<int>(value => progress1.Value = value);
await Task.Run(() =>
{
for (int i = 0; i < 100; i++)
{
((IProgress<int>)progress).Report(i);
Thread.Sleep(50);
}
});
button_prog1.IsEnabled = true;
progress1.Value = 0;
}
private async void Button_prog2_Click(object sender, RoutedEventArgs e)
{
button_prog2.IsEnabled = false;
var progress = new Progress<int>(value => progress2.Value = value);
await Task.Run(() =>
{
for (int i = 0; i < 100; i++)
{
((IProgress<int>)progress).Report(i);
Thread.Sleep(50);
}
});
button_prog2.IsEnabled = true;
progress2.Value = 0;
}
private void Button_close_Click(object sender, RoutedEventArgs e)
{
System.Windows.Application.Current.Shutdown();
}
}
Xaml code
<Grid>
<ProgressBar Name="progress1" Minimum="0" Maximum="100" />
<ProgressBar Name="progress2" Minimum="0" Maximum="100" />
<Button x:Name="button_prog1" Content="Start progress 1" Click="Button_prog1_Click"/>
<Button x:Name="button_prog2" Content="Start progress 2" Click="Button_prog2_Click"/>
<Button x:Name="button_close" Content="Chiudi" Click="Button_close_Click"/>
</Grid>
Thanks for help.
Continue reading...
I am developing a sample wpf application with 2 progess bar, which start independently when the correspond button been clicked.
I achieve this result using c# thread, but now i run into some problems like many c# instructions aren't implemented on vb.net.
Surfing on the internet i found the backgroundworkers solution, but in my view this method is heavy and not good for the thing which i want to do.
Below i attach the working c# and xaml code, and my question is: If this is possible to obtain this in vb.net
C# code
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private async void Button_prog1_Click(object sender, RoutedEventArgs e)
{
button_prog1.IsEnabled = false;
var progress = new Progress<int>(value => progress1.Value = value);
await Task.Run(() =>
{
for (int i = 0; i < 100; i++)
{
((IProgress<int>)progress).Report(i);
Thread.Sleep(50);
}
});
button_prog1.IsEnabled = true;
progress1.Value = 0;
}
private async void Button_prog2_Click(object sender, RoutedEventArgs e)
{
button_prog2.IsEnabled = false;
var progress = new Progress<int>(value => progress2.Value = value);
await Task.Run(() =>
{
for (int i = 0; i < 100; i++)
{
((IProgress<int>)progress).Report(i);
Thread.Sleep(50);
}
});
button_prog2.IsEnabled = true;
progress2.Value = 0;
}
private void Button_close_Click(object sender, RoutedEventArgs e)
{
System.Windows.Application.Current.Shutdown();
}
}
Xaml code
<Grid>
<ProgressBar Name="progress1" Minimum="0" Maximum="100" />
<ProgressBar Name="progress2" Minimum="0" Maximum="100" />
<Button x:Name="button_prog1" Content="Start progress 1" Click="Button_prog1_Click"/>
<Button x:Name="button_prog2" Content="Start progress 2" Click="Button_prog2_Click"/>
<Button x:Name="button_close" Content="Chiudi" Click="Button_close_Click"/>
</Grid>
Thanks for help.
Continue reading...