15,915,160 members
Sign in
Sign in
Email
Password
Forgot your password?
Sign in with
home
articles
Browse Topics
>
Latest Articles
Top Articles
Posting/Update Guidelines
Article Help Forum
Submit an article or tip
Import GitHub Project
Import your Blog
quick answers
Q&A
Ask a Question
View Unanswered Questions
View All Questions
View C# questions
View C++ questions
View Javascript questions
View Visual Basic questions
View Python questions
discussions
forums
CodeProject.AI Server
All Message Boards...
Application Lifecycle
>
Running a Business
Sales / Marketing
Collaboration / Beta Testing
Work Issues
Design and Architecture
Artificial Intelligence
ASP.NET
JavaScript
Internet of Things
C / C++ / MFC
>
ATL / WTL / STL
Managed C++/CLI
C#
Free Tools
Objective-C and Swift
Database
Hardware & Devices
>
System Admin
Hosting and Servers
Java
Linux Programming
Python
.NET (Core and Framework)
Android
iOS
Mobile
WPF
Visual Basic
Web Development
Site Bugs / Suggestions
Spam and Abuse Watch
features
features
Competitions
News
The Insider Newsletter
The Daily Build Newsletter
Newsletter archive
Surveys
CodeProject Stuff
community
lounge
Who's Who
Most Valuable Professionals
The Lounge
The CodeProject Blog
Where I Am: Member Photos
The Insider News
The Weird & The Wonderful
help
?
What is 'CodeProject'?
General FAQ
Ask a Question
Bugs and Suggestions
Article Help Forum
About Us
Search within:
Articles
Quick Answers
Messages
Comments by Member 0123456789 (Top 12 by date)
Member 0123456789
9-Jan-16 6:48am
View
Deleted
The function StartButton_Click is async event handler on some kind of GUI interface and instead of closing any callbacks, it calls another functions (WorkerMethod and PostMessage). The function WorkerMethod is async too and basically wait (simulate some kind of data manipulations), check if there isn't timeout and returns a string. Then the StartButton_Click calls the second function PostMessage, which takes the string and append a property of I guess the GUI interface.
The timeout with the CancellationToken can be useful if you want to timeout the asynchronous function. But with this architecture you will have to write one specific asynchronous containing function with additional two or more specific functions instead of one specific callback closing function and one or more callbacks.
Member 0123456789
9-Jan-16 5:55am
View
I declared and assigned three Task objects for each printName calls and at the end of Main added:
Task.WaitAll(task9000, task6000, task3000);
/* if I need to wait any of the containing callback function to be ready I can just add the below in a synchronous block
task9000.Wait();
or/and
task6000.Wait();
or/and
task3000.Wait();
*/
Main cannot be asynchronous and there is no point of third closing function which will need to be waited anyway.
Member 0123456789
8-Jan-16 16:15pm
View
You're completely right - there will be something else - like piping streams or some kind of manipulating data. With the above code I get error while compiling the code in the console - "Because this call is not awaited, execution of the current method continues before the call is completed. Consider applying the 'await' operator to the result of the call.", while with the code in Solution 1 the compiler doesn't catch it. Both works.
Member 0123456789
8-Jan-16 16:07pm
View
This works perfectly - although probably is really wrong architecture for C#:
public static async Task hello9000(string name, string message)
{
await Task.Run(delegate()
{
Stopwatch timer = new Stopwatch();
timer.Start();
while (timer.ElapsedMilliseconds < 9000)
{
//wait, wait and wait...
}
timer.Stop();
//Console.WriteLine(name);
Console.WriteLine(message);
});
}
public static async Task hello6000(string name, string message)
{
await Task.Run(delegate()
{
Stopwatch timer = new Stopwatch();
timer.Start();
while (timer.ElapsedMilliseconds < 6000)
{
//wait, wait and wait...
}
timer.Stop();
//Console.WriteLine(name);
Console.WriteLine(message);
});
}
public static async Task hello3000(string name, string message)
{
await Task.Run(delegate()
{
Stopwatch timer = new Stopwatch();
timer.Start();
while (timer.ElapsedMilliseconds < 3000)
{
//wait, wait and wait...
}
timer.Stop();
//Console.WriteLine(name);
Console.WriteLine(message);
});
}
public static async Task printName(string name, string message, Func<string, string, Task> callback)
{
Console.WriteLine(name + " started on thread " + System.Threading.Thread.CurrentThread.ManagedThreadId);
await callback(name, message);
}
printName("hello9000", "hello9000 ended on thread " + System.Threading.Thread.CurrentThread.ManagedThreadId, hello9000);
printName("hello6000", "hello6000 ended on thread " + System.Threading.Thread.CurrentThread.ManagedThreadId, hello6000);
printName("hello3000", "hello3000 ended on thread " + System.Threading.Thread.CurrentThread.ManagedThreadId, hello3000);
Member 0123456789
8-Jan-16 15:53pm
View
The function HelloDelay is the closing function for the callback. The function Run is container of Tasks for the callbacks, which are Console.WriteLine. This will only output the messages asynchronously, while I intended a custom callback functions (declared or anonymous), which I can pass separately on a model of callback containing function, so I can call the last asynchronously.
function container(string message, callback)
{
/* do something */
callback(message);//when the above finish call me through function pointer
}
function callback(string message)
{
/* do something */
}
/* do something */
container("hello", callback);//start this without blocking the code
/* do something */
/* ...somewhere in the time and space container function finish... */
Simple as it is, not yet simple for most languages, not build this way.
Member 0123456789
7-Jan-16 12:07pm
View
.NET Framework 4 (lambdas are harder than delegations - but will start using them if it's possible to call function containing callback non-blocking without threads).
Member 0123456789
7-Jan-16 12:03pm
View
Doesn't seem to find the correct information about using callbacks with async/await (the delegation doesn't work);
Member 0123456789
7-Dec-15 2:31am
View
I understand that Web Forms are doing almost everything behind the scene for you and in the MVC you have the full control of managing your resources, although it costs you more time/code and sometimes different approach. Thank you.
Member 0123456789
30-Nov-15 4:05am
View
You're not really answering the question, but the post is really helpful for the beginners. You can set this up from the web.config too - for all cookies. Thanks you.
Member 0123456789
27-Nov-15 1:03am
View
The authentication was already set to anonymous and I've tried the combination without default document - using the ip/Login.aspx and it connects to the Login page, but not further redirects to Main.aspx. The whole situation works in Visual Studion and the cookie as you can see is session - you can see it at the browser too. I'm allowing it in both - VS and IIS. If I turn off the cookie check and visit directly the Main.aspx in IIS by typing ip/Main.aspx I can reach it, but I can't redirect it through the Login.aspx.
Member 0123456789
27-Nov-15 0:47am
View
Login.aspx is set as the default document and I've tried using Main.aspx, including it with Login.aspx, changing the order and excluding it, but it's still refresh the page, when I press the button which execute the redirect code.
Member 0123456789
5-Nov-15 4:55am
View
Thanks you - it was simple solution at the end.
I've used System.Diagnostics.StopWatch and the connection and query execution with the table filling was taking under half a second, but the control rendering was taking sometimes more than 1-2 minutes. The DataGridViewControl, which I was copying from one place to another had the setting to autoresize each cell by its content. For the console rendering is taking around 1-3 seconds with StringBuilder.
Thanks you again.
Show More