PDA

View Full Version : متوقف کردن دانلود سیستم



mousa1992
جمعه 20 مرداد 1391, 08:25 صبح
سلام دوستان
راهی رو سراغ دارید با سی شارپ دانلود رو متوقف کرد؟

nunegandom
جمعه 20 مرداد 1391, 13:46 عصر
اگه بتونی پورت رو پیدا کنی، با این دستور میتونی پورت رو ببندی
تویه CMD:
netsh firewall delete portopening protocol = TCP port = 445

mousa1992
جمعه 20 مرداد 1391, 23:43 عصر
ممنون دوست عزیز
ممکنه بیشتر توضیح بدید؟
هر برنامه دانلود از پورت خاصی استفاده میکنه درسته ؟
در این صورت باید پورت ها رو معرفی کنم به برنامه و همه رو ببندم

nunegandom
شنبه 21 مرداد 1391, 17:26 عصر
:متفکر:
اگه از نود۳۲ استفاده کرده باشید، یه قسمت داره ماله مانیتور کردن برنامه ها، میتونید ببینید چه برنامه هایی از چه پرت هایی استفاده میکنند.در کل اطلاعات بیشتری در این باره ندارم :ناراحت:
اینجا رو ببین
http://alturl.com/79xej

tooraj_azizi_1035
یک شنبه 22 مرداد 1391, 22:06 عصر
سلام
ببین شما می تونی با استفاده از CancellationToken که برای انصراف از ادامه یک کار که در پس زمینه در حال اجراست استفاده کنی:


namespace CancellationWithOCE
{
using System;
using System.Threading;
using System.Threading.Tasks;

class Program
{
static void Main(string[] args)
{
Console.WriteLine("Press any key to start. Press 'c' to cancel.");
Console.ReadKey();

var tokenSource = new CancellationTokenSource();
var token = tokenSource.Token;

// Store references to the tasks so that we can wait on them and
// observe their status after cancellation.
Task[] tasks = new Task[10];

// Request cancellation of a single task when the token source is canceled.
// Pass the token to the user delegate, and also to the task so it can
// handle the exception correctly.
tasks[0] = Task.Factory.StartNew(() => DoSomeWork(1, token), token);

// Request cancellation of a task and its children. Note the token is passed
// to (1) the user delegate and (2) as the second argument to StartNew, so
// that the task instance can correctly handle the OperationCanceledException.
tasks[1] = Task.Factory.StartNew(() =>
{
// Create some cancelable child tasks.
for (int i = 2; i < 10; i++)
{
// For each child task, pass the same token
// to each user delegate and to StartNew.
tasks[i] = Task.Factory.StartNew(iteration =>
DoSomeWork((int)iteration, token), i, token);
}
// Passing the same token again to do work on the parent task.
// All will be signaled by the call to tokenSource.Cancel below.
DoSomeWork(2, token);
}, token);

// Give the tasks a second to start.
Thread.Sleep(1000);

// Request cancellation from the UI thread.
if (Console.ReadKey().KeyChar == 'c')
{
tokenSource.Cancel();
Console.WriteLine("\nTask cancellation requested.");

// Optional: Observe the change in the Status property on the task.
// It is not necessary to wait on tasks that have canceled. However,
// if you do wait, you must enclose the call in a try-catch block to
// catch the OperationCanceledExceptions that are thrown. If you do
// not wait, no OCE is thrown if the token that was passed to the
// StartNew method is the same token that requested the cancellation.

#region Optional_WaitOnTasksToComplete
try
{
Task.WaitAll(tasks);
}
catch (AggregateException e)
{
// For demonstration purposes, show the OCE message.
foreach (var v in e.InnerExceptions)
Console.WriteLine("msg: " + v.Message);
}

// Prove that the tasks are now all in a canceled state.
for (int i = 0; i < tasks.Length; i++)
Console.WriteLine("task[{0}] status is now {1}", i, tasks[i].Status);
#endregion
}

// Keep the console window open while the
// task completes its output.
Console.ReadLine();
}

static void DoSomeWork(int taskNum, CancellationToken ct)
{
// Was cancellation already requested?
if (ct.IsCancellationRequested)
{
Console.WriteLine("We were cancelled before we got started.");
Console.WriteLine("Press Enter to quit.");
ct.ThrowIfCancellationRequested();
}
int maxIterations = 1000;

// NOTE!!! A benign "OperationCanceledException was unhandled
// by user code" error might be raised here. Press F5 to continue. Or,
// to avoid the error, uncheck the "Enable Just My Code"
// option under Tools > Options > Debugging.
for (int i = 0; i < maxIterations; i++)
{
// Do a bit of work. Not too much.
var sw = new SpinWait();
for (int j = 0; j < 3000; j++) sw.SpinOnce();
Console.WriteLine("...{0} ", taskNum);
if (ct.IsCancellationRequested)
{
Console.WriteLine("bye from {0}.", taskNum);
Console.WriteLine("\nPress Enter to quit.");

ct.ThrowIfCancellationRequested();
}
}
}
}
}



در این برنامه 10 ترد ایجاد میشه که هر ترد متد DoSomeWork رو اجرا می کنه که می تونه دانلود شما باشه پس از یک ثانیه انتظار اگر کلید c فشار داده بشه همه کارها متوقف میشن.