TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
pintu patil
NA
3
6.1k
How to end Running task immediadtely
Sep 26 2012 2:38 AM
namespace WindowsFormsApplication3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public int q;
SoundPlayer player = new SoundPlayer();
public void Test(int flag)
{
CancellationTokenSource tokenSource = new CancellationTokenSource();
CancellationToken token = tokenSource.Token;
var u=Task.Factory.StartNew(()=>
{
if (token.IsCancellationRequested)
{
player.Stop();
throw new OperationCanceledException(token);
}
else
{
player.SoundLocation=@"D:\AudioOut\final.wav";
{
for (int i = 0; i < 2; i++)
{
player.PlaySync();
}
}
}
}, token);
if (flag == 1)
{
u.Start();
}
else if(flag==0)
{
token.ThrowIfCancellationRequested();
tokenSource.Cancel();
u.Dispose();
}
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
Test(1);
}
private void Show_Click(object sender, EventArgs e)
{
MessageBox.Show(" askdsa;kd;aslkdsa;ldk;asldk");
}
private void Stop_Click(object sender, EventArgs e)
{
Test(0);
}
}
}
i want to stop PlaySync immediately.But not working.using cancel method task will assign id other than from running task id.and cancel differnet task not a running task i.e. playsync
plz provide solution
Reply
Answers (
0
)
How can we access multiple appSettings from App.config
Print Multiple Bill On Single Click