|
Your FTPFile method returns a string. You're trying to put it in a Task of string.
This space for rent
|
|
|
|
|
You should avoid async void methods wherever possible:
Avoid async void methods - You’ve Been Haacked[^]
Async/Await - Best Practices in Asynchronous Programming[^]
Also, sftp.UploadFileAsync implies that the method returns before the upload has completed. Does this method return a Task , or does it raise an UploadFileCompleted event? If it raises an event (EAP pattern), you can wrap that in a Task -returning method, and make your FTPFile method async as well.
How to: Wrap EAP Patterns in a Task[^]
Tasks and the Event-based Asynchronous Pattern | Parallel Programming with .NET[^]
public static class SFTPExtensions
{
public static Task UploadFileTaskAsync(this SFTP sftp, string fileName, string remoteFile)
{
var tcs = new TaskCompletionSource<bool>();
UploadFileCompletedEventHandler handler = null;
handler = (sender, args) =>
{
if (args.Cancelled)
{
tcs.TrySetCancelled();
}
else if (args.Error != null)
{
tcs.TrySetException(args.Error);
}
else
{
tcs.TrySetResult(true);
}
sftp.UploadFileCompleted -= handler;
};
sftp.UploadFileCompleted += handler;
try
{
sftp.UploadFileAsync(fileName, remoteFile);
}
catch (Exception ex)
{
sftp.UploadFileCompleted -= handler;
tcs.TrySetException(ex);
}
return tcs.Task;
}
}
public static async Task FileReceived(string fileName)
{
string result = await FTPFile(fileName).ConfigureAwait(false);
await FileUploaded(result).ConfigureAwait(false);
}
private static async Task<string> FTPFile(string fileName)
{
string remoteFile = Path.GetFileName(fileName);
SFTP sftp = new SFTP(_address, _userName, _password);
await sftp.UploadFileTaskAsync(fileName, remoteFile).ConfigureAwait(false);
return fileName;
}
private static async Task FileUploaded(string fileName)
{
...
}
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
public partial class BlinkLabel : Label {
private CancellationTokenSource ts;
private Task task1;
public BlinkLabel()
{
InitializeComponent();
}
public void StartBlink()
{
ts=new CancellationTokenSource();
CancellationToken ct = ts.Token;
if ( isRunningTask(task1) ) return;
task1 = Task.Factory.StartNew(() =>
{
while (true)
{
ct.ThrowIfCancellationRequested();
Thread.Sleep(500);
Visible = !Visible;
}
}, ct);
blinkTask.ContinueWith(t =>
{
Visible = false;
},TaskContinuationOptions.None);
}
public void StopBlink()
{
ts.Cancel();
}
}
public partial class MainForm: Form
{
public MainForm
{
InitializeComponent();
blinkLabel1.Text="Blinking message...";
blinkLabel1.StartBlink();
blinkLabel1.StopBlink();
}
}
I have some question:
1- why cancel request doesn't work?
2- how we can debug parallel program? when i use Ctrl+F5 the program works, when use F5 invoke errors occured.
3- Does exist better way to create blinkLable user control instead Task?
please get a solution for this problem, i don't have enough experience in parallel programming. thanks/.
|
|
|
|
|
Programmer 1 wrote: 1- why cancel request doesn't work? Dunno, but it looks like you are throwing an exception inside a new thread without handling it.
Programmer 1 wrote: 2- how we can debug parallel program? when i use Ctrl+F5 the program works, when use F5 invoke errors occured. Walkthrough: Debugging a Parallel Application[^]
Programmer 1 wrote: 3- Does exist better way to create blinkLable user control instead Task? If all you need is a blink-label, use a timer and not a thread.
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
can you edit my code to solve problem one, i couldn't understand. thank you
|
|
|
|
|
Programmer 1 wrote: can you edit my code to solve problem one No.
Programmer 1 wrote: i couldn't understand. Which part?
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
try
{
WebRequest request = WebRequest.Create("http://facebook.com");
HttpWebResponse response = (HttpWebResponse) request.GetResponse();
MessageBox.Show("I am here!");
}
catch (Exception ex)
{
MessageBox.Show("Error Occurred!");
}
In my country facebook is filtered and When I run this code, no exceptions will be throw, also program not display message "I am here!";
What happened?
I want to use this code in a timer_tick every 1 minute and update ui label with alive status. do you have alternative way?
|
|
|
|
|
You'll have to use the debugger to be sure, but at a guess the request.GetResponse is not returning.
It's a blocking call, so if the response doesn't complete properly, then it'll never return: HttpWebRequest.GetResponse Method (System.Net)[^]
"This method blocks waiting for content to post; if there is no time-out set and you do not provide content, the calling thread blocks indefinitely."
Since what you are trying to do is probably illegal in your country (or FarceBook wouldn't be filtered) you probably need to think long and hard before looking at alternative approaches such as proxies.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
thanks. the problem was timeout. my timer_tick interval value was less than default timeout for request and before timer_tick completion, next round of timer called.
|
|
|
|
|
Hi
I want to display alert in system tray using c#.
Message is shown in popup window (like form) ,fetched from database
it will be displayed for 10 seconds
If user forget to see ,it will be displayed as icon in the system tray
and clicking can be opened to see the popup window.
Please help me.
It is urgent.
Regards
Rama
|
|
|
|
|
WPF? Windows Forms? Running purely as a Windows service?
Have a search for NotifyIcon to get the general idea of what you're trying to do. I have done a starter search for you here[^].
This space for rent
|
|
|
|
|
First of all, we're volunteers, and yours is as urgent as every other post. Second, it looks like a set of requirements, a rough description of what the app should do. We can help if you are stuck in building it and have specific questions, but it is not a place to order free code
Bastard Programmer from Hell
If you can't read my code, try converting it here[^]
|
|
|
|
|
hi,
i want to create my on language translator in C# this is my university project i do not know how to start how to implement statistical machine translation algorithm in c#. can you please guide me and give me helping material to complete this task
Thanks
Abdullah Khalil
[DELETED]@gmail.com
[DELETED]@skype.com
modified 23-Sep-16 4:57am.
|
|
|
|
|
Programming language translator? Human language translator?Member 10517704 wrote: i do not know how to start how to implement statistical machine translation algorithm in c# Do you know how to use Google? Why don't you search around there and see what you can find - the research you do will be useful to you.
Finally, remove your email and Skype addresses unless you really, really want to be spammed.
This space for rent
|
|
|
|
|
i think google also use machine translator technique and this is my University task to create on translator
|
|
|
|
|
So what have you done so far? What research have you undertaken?
I have to say that I admire the breadth of your ambition - the teams at Microsoft, Google, etc, have spent years with teams of PhDs and postgraduate researchers slaving away.
This space for rent
|
|
|
|
|
i have just read Statistical Machine Translation article nothing else
|
|
|
|
|
One article or multiple articles on that subject?
This space for rent
|
|
|
|
|
|
Then I'm afraid that you have probably taken on a much bigger project than you can manage. As others have said here, you're better off looking for a project that is more to your skill level. When you do a final project, you show off the skills that you have learnt; it's never meant to be about taking on something you have no idea about.
This space for rent
|
|
|
|
|
This is a project of immense complexity. I highly suggest you pick another project, one that you can finish within the school year.
If you have to start a project by begging for tutorials in a forum and starting your "questions" with the phrase "I have no idea where to start" you've got a huge problem.
|
|
|
|
|
You are indeed a master of understatement!
He's either a damn sight better than I was at his age, or he hasn't realised that it's just a bit complicated to implement natural language translation...
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|
|
The mind boggles!
PS: Was wanting to talk with you regarding that little bit of space you have in your sig for rent ...
|
|
|
|
|
Reasonable Rates.
This space for rent
|
|
|
|
|
Never post your email address in any forum, unless you really like spam! If anyone replies to you, you will receive an email to let you know.
I've removed them from your message.
Bad command or file name. Bad, bad command! Sit! Stay! Staaaay...
|
|
|
|