با سلام
یک فرم WPF رو وقتی با زدن کلید F11 شروع به دیباگ می شه از متد DoWork خیلی راحت رد می شه و توی متد bw_ProgressChanged گیر می کنه، دلیلش چیه؟
با تشکر
متن کد:
<left>
using System; using System.Collections.Generic; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; namespace WpfApplication2 { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void Window_Loaded(object sender, RoutedEventArgs e) { bw.WorkerReportsProgress = true; bw.WorkerSupportsCancellation = true; bw.DoWork += bw_DoWork; bw.ProgressChanged += bw_ProgressChanged; bw.RunWorkerCompleted += bw_RunWorkerCompleted; bw.RunWorkerAsync(); } #region bw private BackgroundWorker bw = new BackgroundWorker(); bool flg = true; int tempSec = 0; private void bw_DoWork(object sender, DoWorkEventArgs e) { while (flg) { if (tempSec < DateTime.Now.Second) { tempSec = DateTime.Now.Second; bw.ReportProgress(tempSec); } } } private void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { txtSecondCounter.Text = "Done"; /* if (!e.Cancelled && e.Error == null)//Check if the worker has been cancelled or if an error occured { string result = (string)e.Result;//Get the result from the background thread lblAlarm.Text = result;//Display the result to the user lblCounter.Content = "Done"; lblCounterTimes.Content = (++countTimes).ToString(); m_Timer.Dispose(); if ((bool)chkLoop.IsChecked) btnStart_Click(btnStart, null); } else if (e.Cancelled) { lblAlarm.Text = "User Cancelled"; } else { lblCounter.Content = "An error has occured"; } btnStart.IsEnabled = true; */ } private void bw_ProgressChanged( object sender, ProgressChangedEventArgs e) { txtSecondCounter.Text = e.ProgressPercentage.ToString(); } #endregion private void btnPlayPause_Click(object sender, RoutedEventArgs e) { flg = !flg; if (flg) bw.RunWorkerAsync(); if (btnPlayPause.Content.ToString() == "Pause") btnPlayPause.Content = "Play"; else btnPlayPause.Content = "Pause"; } } }
<left> و
و این هم کد xmal اش:
<Window x:Class="WpfApplication2.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:WpfApplication2" mc:Ignorable="d" Title="MainWindow" Height="350" Width="525" Loaded="Window_Loaded" > <DockPanel Name="pnlMain" LastChildFill="False"> <DockPanel DockPanel.Dock="Top" Height="40" Background="AliceBlue" LastChildFill="False"> </DockPanel> <DockPanel DockPanel.Dock="Bottom" Height="40" Background="AliceBlue" LastChildFill="False"> <TextBlock Name="txtSecondCounter" Width="100" Height="30" Background="Yellow">0</TextBlock> <Button Width="100" Name="btnPlayPause" Click="btnPlayPause_Click" DockPanel.Dock="Left">Pause</Button> <TextBox Width="100"></TextBox> </DockPanel> </DockPanel> </Window>
این پست در تاریخ {{ dateString(new Date(post.deleteDate)) }} توسط {{ post.deletedByUser }} حذف شده است.
دلیل حذف: {{ post.deleteReason ?? 'نامشخص' }}
زمان پاسخ گویی روز های شنبه الی چهارشنبه ساعت 9 الی 18
فقط به موضوعات مربوط به محصولات آموزشی و فروش پاسخ داده می شود