|
Hi.
if i have
class Program
{
static void Main(string[] args)
{
Task task1 = Task.Factory.StartNew(() => doStuff());
Task task2 = Task.Factory.StartNew(() => doStuff());
Task task3 = Task.Factory.StartNew(() => doStuff());
Task.WaitAll(task1, task2, task3);
Console.WriteLine("All threads complete");
}
static void doStuff()
{
//do stuff here
}
}
how i stop only one, anyone?
how i stop task2 only, for example?
|
|
|
|
|
This not help ? Task Cancellation[^]
Every day, thousands of innocent plants are killed by vegetarians.
Help end the violence EAT BACON
|
|
|
|
|
The standard way to do this is to use a CancellationToken from a CancellationTokenSource for each one that you want to cancel. You assign this token when you create your task. Your code would look something like this:
private IDictionary<string, CancellationTokenSource> taskToCancellationToken = new Dictionary<string, CancellationTokenSource>();
private Task DoSomething(string taskName, Action operation)
{
CancellationTokenSource tokenSource = new CancellationTokenSource();
taskToCancellationToken.Add(taskName, tokenSource);
return Task.Factory.StartNew(operation, tokenSource.Token);
} Then, you can simply do something like this
public void QueueTasks()
{
Task.WaitAll(DoSomething("Task1", doStuff), DoSomething("Task2", doStuff), DoSomething("Task3", doStuff));
}
private void doStuff()
{
taskToCancellationToken["Task2"].Cancel();
}
This space for rent
|
|
|
|
|
if the "some signal" exists only on the QueueTasks func, how i Cancel the task? i can call taskToCancellationToken["Task2"].Cancel() from there and will work?
|
|
|
|
|
As soon as you hit WaitAll, you are telling the system to wait for the tasks to complete somehow. This means you're going to have to cancel the task from inside the running task - which is why I put it inside the running task.
This space for rent
|
|
|
|
|
So, may i use Thread instead? because i can stop it from outside the running code.
|
|
|
|
|
Yes, you can, but you're not buying yourself anything by doing so.
You're still going to have to signal the thread to stop and if your code outside the thread is blocked waiting for the thread(s) to finish its/their task(s), how is your outside code going to cancel that thread?
You won't buy yourself an easier solution by using a thread. You end up with the exact same problem, just using different classes.
|
|
|
|
|
I have a label displaying some content in listview item. When a user double clicks the label, it should enable a user to change the listview content.
Check the image here
If user double click the first name (check the image), it should enable a user to change the first name. Is there a simpler way to do this?
Thanks!
|
|
|
|
|
Looks like this[^] CP article might help you.
"You'd have to be a floating database guru clad in a white toga and ghandi level of sereneness to fix this goddamn clusterfuck.", BruceN[ ^]
|
|
|
|
|
lllllllllllllllllllllllll
modified 6-Jan-16 12:26pm.
|
|
|
|
|
WHAT? You're question made no sense at all and, without any context information, is impossible to figure out what you're talking about.
All anyone knows is that you have a Windows Forms application and you're having some kind of problem with what appears to be the OpenFile dialog.
|
|
|
|
|
Maybe take Dictionary and see what PREVIOUS OPEN.
|
|
|
|
|
Calm down. Like others, I have read your original post and don't really understand what you are asking for. Now, I appreciate that you aren't a native English speaker, so the terms you are using might not be exactly what you think they mean. When you talk about previous open, are you talking about a form that has been closed and that you are loading again? Is it a window that's already open and you have Control-Tabbed to get to it?
This space for rent
|
|
|
|
|
I think - but I'm not sure - that he is processing a file and then when his code tries to do something with it again, it locks up. If so, Nathan is probably right that he isn't closing and disposing of streams / handles but without relevant code...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
What he means is that all of the individual words make sense: it's when you put them together as a question it isn't understandable!
Please, remember that we can't see your screen, access your HDD, or read your mind - we only get exactly what you tell us to work with. I can get some bits from it - you have a WinForms app that seems to get stuck when you do something with files, but we don't know what you are doing with them, or how you are doing it in your code. So we ask for clarification - because we are trying to understand your problem in enough detail to help you!
We understand that English may not be your first language, and we are trying to work with you here - but we can't sort out a problem if we don't understand the question!
As a suggestion, try typing the question in your native language with a good level of detail and use Google Translate to convert it - it may make more sense to us that way!
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
What?!
There are only 10 types of people in the world, those who understand binary and those who don't.
|
|
|
|
|
Are only 2 people.
#1 Who pretend it's GURU.
#2 SHE ,HE it's GURU.
In Forum 99% pretend are GURU.
|
|
|
|
|
|
Make sure to dispose of your file streams when you've used them. You're probably leaving dangling handles all over the place. Sort of like an acrobat, but it's more of an abstract reference.
|
|
|
|
|
There's probably something wrong in the Multi-channelled neutral superstructure or the Secured zero tolerance framework. You need to reset the Switchable discrete superstructure to fix it.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
Yup and that makes as much sense as the op, you must be the one real guru!
Never underestimate the power of human stupidity
RAH
|
|
|
|
|
It's all in the wrist.
What do you get when you cross a joke with a rhetorical question?
The metaphorical solid rear-end expulsions have impacted the metaphorical motorized bladed rotating air movement mechanism.
Do questions with multiple question marks annoy you???
|
|
|
|
|
Hello,
I wrote a program in C# using VS2010 that has a media page that pulls videos from You Tube. It worked perfectly until this morning. Today, all I get is a blank screen. Even if I get straight to the basics and hard code a movie file into the properties menu, all I get is a blank screen. The only thing that I can see that might have happened is that the program did the newest Windows update (Windows 10) last night automatically. To check this theory, I had a previous version of the application on my laptop that also runs Windows 10 .... so I checked it out and my older version of the same app running on the not updated Windows computer works perfectly. It seems that Windows 10 has destroyed something in the Flash support, maybe the Flash.ocx file? I really don't know. I was supposed to launch this application at the end of this week, so this is a major issue now. I don't know how to repair this. Appreciate any help. Thank You, Pat.
|
|
|
|
|
You made a HUGE mistake by relying on Flash. Flash is dying, fast. YouTube's default video player has been HTML5 video for about the last year.
On top of that, what you're doing violates the YouTube terms of service. Using any other play other than that supplied by YouTube is expressly forbidden unless excepted by written authorization by YouTube. Good luck getting that.
Yeah, Flash is updated by Windows Update on Windows 8 and above. It's no longer handled by Adobe and, frankly, Adobe is shutting down support for Flash except for gaming and "premium video", which does not apply to YouTube.
YouTube reserves the right to change their support and how they deliver video at any time and has done so multiple times in the past to prevent you from using your own player. What works today is in no way guaranteed to work tomorrow.
|
|
|
|
|
Dave,
Thank you for your input and response. I am fortunate that someone with your depth of knowledge and credentials took the time to bring me up to date. Since my use is for an application and not a webpage, HTML5 is and never was a solution for me. I understand the legalities and I thank you for bringing it to my attention, but I don't think that there are less than 100 videos posted ON YouTube that explain how to use the Shock-wave Viewer in a C# form to view the content of videos posted on You Tube. Like most things today, and as You Tube already knows (or has found out), as quick as they make a change there will be some one with a new key for the lock. It is not possible to post something in the public domain without having someone else contrive a way to get around it. That said, I prefer to do it right and I will simply have to find (or create) a service and/or system that will let me continue to have videos viewed privately from within proprietary software. Perhaps I will change the videos to (mp4) and host them on my own server. Then I can use the Microsoft Media player that already has libraries in Visual Studio. In my case, the most disturbing thing was the timing. Thank You Again. I would like to be able to call on you for advice and perhaps even do some work for me if you are interested. Best Regards, Pat.
|
|
|
|