Search Results

Search found 1226 results on 50 pages for 'asynchronous'.

Page 5/50 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • Where do I handle asynchronous exceptions?

    - by Jurily
    Consider the following code: class Foo { // boring parts omitted private TcpClient socket; public void Connect(){ socket.BeginConnect(Host, Port, new AsyncCallback(cbConnect), quux); } private void cbConnect(IAsyncResult result){ // blah } } If socket throws an exception after BeginConnect returns and before cbConnect gets called, where does it pop up? Is it even allowed to throw in the background?

    Read the article

  • Asynchronous IO in Java?

    - by thr
    What options for async io (socket-based) are there in java other then java.nio? Also does java.nio use threads in the backround (as I think .NET's async-socket-library does, maybe it's been changed) or is it "true" async io using a proper select call?

    Read the article

  • How does one implement a truly asynchronous java thread

    - by Ritesh M Nayak
    I have a function that needs to perfom two operations, one which finishes fast and one which takes a long time to run. I want to be able to delegate the long running operation to a thread and I dont care when the thread finishes, but the threads needs to complete. I implemented this as shown below , but, my secondoperation never gets done as the function exits after the start() call. How I can ensure that the function returns but the second operation thread finishes its execution as well and is not dependent on the parent thread ? public void someFunction(String data) { smallOperation() Blah a = new Blah(); Thread th = new Thread(a); th.Start(); } class SecondOperation implements Runnable { public void run(){ // doSomething long running } }

    Read the article

  • Typesafe fire-and-forget asynchronous delegate invocation in C#

    - by LBushkin
    I recently found myself needing a typesafe "fire-and-forget" mechanism for running code asynchronously. Ideally, what I would want to do is something like: var myAction = (Action)(() => Console.WriteLine("yada yada")); myAction.FireAndForget(); // async invocation Unfortunately, the obvious choice of calling BeginInvoke() without a corresponding EndInvoke() does not work - it results in a slow resource leak (since the asyn state is held by the runtime and never released ... it's expecting an eventual call to EndInvoke(). I also can't run the code on the .NET thread pool because it may take a very long time to complete (it's advised to only run relatively short-lived code on the thread pool) - this makes it impossible to use the ThreadPool.QueueUserWorkItem(). Initially, I only needed this behavior for methods whose signature matches Action, Action<...>, or Func<...>. So I put together a set of extension methods (see listing below) that let me do this without running into the resource leak. There are overloads for each version of Action/Func. Unfortunately, I now want to port this code to .NET 4 where the number of generic parameters on Action and Func have been increased substantially. Before I write a T4 script to generate these, I was also hoping to find a simpler more elegant way to do this. Any ideas are welcome. public static class AsyncExt { public static void FireAndForget( this Action action ) { action.BeginInvoke(OnActionCompleted, action); } public static void FireAndForget<T1>( this Action<T1> action, T1 arg1 ) { action.BeginInvoke(arg1, OnActionCompleted<T1>, action); } public static void FireAndForget<T1,T2>( this Action<T1,T2> action, T1 arg1, T2 arg2 ) { action.BeginInvoke(arg1, arg2, OnActionCompleted<T1, T2>, action); } public static void FireAndForget<TResult>(this Func<TResult> func, TResult arg1) { func.BeginInvoke(OnFuncCompleted<TResult>, func); } public static void FireAndForget<T1,TResult>(this Func<T1, TResult> action, T1 arg1) { action.BeginInvoke(arg1, OnFuncCompleted<T1,TResult>, action); } // more overloads of FireAndForget<..>() for Action<..> and Func<..> private static void OnActionCompleted( IAsyncResult result ) { var action = (Action)result.AsyncState; action.EndInvoke(result); } private static void OnActionCompleted<T1>( IAsyncResult result ) { var action = (Action<T1>)result.AsyncState; action.EndInvoke( result ); } private static void OnActionCompleted<T1,T2>(IAsyncResult result) { var action = (Action<T1,T2>)result.AsyncState; action.EndInvoke(result); } private static void OnFuncCompleted<TResult>( IAsyncResult result ) { var func = (Func<TResult>)result.AsyncState; func.EndInvoke( result ); } private static void OnFuncCompleted<T1,TResult>(IAsyncResult result) { var func = (Func<T1, TResult>)result.AsyncState; func.EndInvoke(result); } // more overloads of OnActionCompleted<> and OnFuncCompleted<> }

    Read the article

  • Web service performing asynchronous call

    - by kornelijepetak
    I have a webservice method FetchNumber() that fetches a number from a database and then returns it to the caller. But just before it returns the number to the caller, it needs to send this number to another service so instantiates and runs the BackgroundWorker whose job is to send this number to another service. public class FetchingNumberService : System.Web.Services.WebService { [WebMethod] public int FetchNumber() { int value = Database.GetNumber(); AsyncUpdateNumber async = new AsyncUpdateNumber(value); return value; } } public class AsyncUpdateNumber { public AsyncUpdateNumber(int number) { sendingNumber = number; worker = new BackgroundWorker(); worker.DoWork += asynchronousCall; worker.RunWorkerAsync(); } private void asynchronousCall(object sender, DoWorkEventArgs e) { // Sending a number to a service (which is Synchronous) here } private int sendingNumber; private BackgroundWorker worker; } I don't want to block the web service (FetchNumber()) while sending this number to another service, because it can take a long time and the caller does not care about sending the number to another service. Caller expects this to return as soon as possible. FetchNumber() makes the background worker and runs it, then finishes (while worker is running in the background thread). I don't need any progress report or return value from the background worker. It's more of a fire-and-forget concept. My question is this. Since the web service object is instantiated per method call, what happens when the called method (FetchNumber() in this case) is finished, while the background worker it instatiated and ran is still running? What happens to the background thread? When does GC collect the service object? Does this prevent the background thread from executing correctly to the end? Are there any other side-effects on the background thread? Thanks for any input.

    Read the article

  • Multilevel asynchronous method call pattern in c#

    - by michajas
    Hi, I have design problem regarding async calls to method. I'd like to know best/good pattern to call async method, which calls another async method, which calls another async method :) In other words, I have WCF service reference created with async methods and I want to call them from another async method which is called by other async method. All this for non blocking GUI. Thanks!

    Read the article

  • Asynchronous database update in Django?

    - by Mark
    I have a big form on my site. When the users fill it out and submit it, most of the data just gets dumped to the database, and then they get redirected to a new page. However, I'd also like to use the data to query another site, and then parse the results. That might take a bit longer. It's not essential that the user sees these results right away, so I was wondering if it's possible to asynchronously call a function that will handle this, and then return an HttpResponse from my view like usual without making them wait? If so... how? Any particular libraries I should look at?

    Read the article

  • asynchronous calls in asp.net

    - by lockedscope
    in this sample, two threads created; a worker thread created by BeginInvoke and an I/O completion thread created by SendAsync method. but another author in his UnsafeQueueNativeOverlapped example, don't recommend this. i want to use SendAsync or ...Async in an asp.net page and i want to use PageAsyncTask. however, its BeginEventHandler requires AsyncResult to be returned which SendAsync does not return. afaik, event based async pattern is the most recommended way so how could we call SendAsync or any ...Async methods without creating two threads and hurting the performance?

    Read the article

  • Workflow Foundation: Asynchronous operations (lengthy network I/O)

    - by StormianRootSolver
    I have to create an application that will be started a few times per day (it's non - interactive). To operate, it needs LARGE amounts of data from the Internet (megabytes) via a rather slow connection, so the WCF service calls take quite some time. At the same time, it needs to perform local calculations and has a sophisticated initialization process. So, what I want to do is to create a workflow that asynchronously fetches the data (takes a few minutes) while already initializing / calculating locally. Is there a way to accomplish this?

    Read the article

  • How does jQuery have asynchronous functions?

    - by Sam.Rueby
    I'm surprised I can't find a clear answer to this. So, in jQuery, you can do this: $(someElements).fadeOut(1000); $(someElements).remove(); Which, will start a fadeOut animation, but before it finishes executing in the 1 second duration, the elements are removed from the DOM. But how is this possible? I keep reading the JavaScript is single threaded. ( Is javascript guaranteed to be single-threaded? ) This question is not "How do I fix this?" I know I can do either: $(someElements).fadeOut(1000).promise().done(function() { $(someElements).remove();});, or even better:$(someElements).fadeOut(1000, function() { $(this).remove(); } ); What I don't understand is how JavaScript runs in a "single thread" but I'm able to use these jQuery functions that execute asynchronously and visibly see the DOM change in different places at the same time. How does it work?

    Read the article

  • Action T synchronous and asynchronous

    - by raffaeu
    Hi everybody I have a contextmenustrip control that allows you to execute an action is two different flawours. Sync and Async. I am trying to covert everything using Generics so I did this: public class BaseContextMenu<T> : IContextMenu { private T executor ... public void Exec(Action<T> action){ action.Invoke(this.executor); } public void ExecAsync(Action<T> asyncAction){ ... } How I can write the async method in order to execute the generic action and 'do something' with the menu in the meanwhile? I saw that the signature of BeginInvoke is something like: asyncAction.BeginInvoke(thi.executor, IAsyncCallback, object);

    Read the article

  • Asynchronous SQL Operations

    - by Paul Hatcherian
    I've got a problem I'm not sure how best to solve. I have an application which updates a database in response to ad hoc requests. One request in particular is quite common. The request is an update that by itself is quite simple, but has some complex preconditions. For this request the business layer first requests a set of data from the data layer. The business logic layer evaluated the data from the database and parameters from the request, from this the action to be performed is determined, and the request's response message(s) are created. The business layer now executes the actual update command that is the purpose of the request. This last step is the problem, this command is dependent on the state of the database, which might have changed since the business logic ran. Locking down the data read in this operation across several round-trips to the database doesn't seem like a good idea either. Is there a 'best-practice' way to accomplish something like this? Thanks!

    Read the article

  • How to call a method after asynchronous task is complete

    - by doctordoder
    I have a class called WikiWebView which is a subclass of UIWebView which loads Wikipedia subjects and is designed to fetch all the links of the webpage, in order to create a sort of site map for the subject. My problem is that I can only create the links once the web page has loaded, but the loading isn't done right after [self loadRequest:requestObj] is called. - (void)loadSubject:(NSString *)subject { // load the actual webpage NSString *wiki = @"http://www.wikipedia.org/wiki/"; NSString *fullURL = [wiki stringByAppendingString:subject]; NSURL *url = [NSURL URLWithString:fullURL]; NSURLRequest *requestObj = [NSURLRequest requestWithURL:url]; [self loadRequest:requestObj]; // [self createLinks]; // need this to be called after the view has loaded } - (void)createLinks { NSString *javascript = @"var string = \"\";" "var arr = document.getElementsByClassName(\"mw-redirect\");" "for (var i = 0; i < arr.length; ++i)" "{" "var redirectLink = arr[i].href;" "string = string + redirectLink + \" \";" "}" "string;"; NSString *links = [self stringByEvaluatingJavaScriptFromString:javascript]; self.links = [links componentsSeparatedByString:@" "]; } I tried the normal delegation technique, which lead to this code being added: - (id)init { if (self = [super init]) { self.delegate = self; // weird } return self; } #pragma mark - UIWebViewDelegate - (void)webViewDidStartLoad:(UIWebView *)webView { ++_numProcesses; } - (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error { --_numProcesses; } - (void)webViewDidFinishLoad:(UIWebView *)webView { --_numProcesses; if (_numProcesses == 0) { [self createLinks]; } } However, the delegate methods are never called.. I've seen similar questions where the answers are to use blocks, but how would I do that in this case?

    Read the article

  • ASP.NET Asynchronous Pages and when to use them

    - by rajbk
    There have been several articles posted about using  asynchronous pages in ASP.NET but none of them go into detail as to when you should use them. I finally found a great post by Thomas Marquardt that explains the process in depth. He addresses a key misconception also: So, in your ASP.NET application, when should you perform work asynchronously instead of synchronously? Well, only 1 thread per CPU can execute at a time.  Did you catch that?  A lot of people seem to miss this point...only one thread executes at a time on a CPU. When you have more than this, you pay an expensive penalty--a context switch. However, if a thread is blocked waiting on work...then it makes sense to switch to another thread, one that can execute now.  It also makes sense to switch threads if you want work to be done in parallel as opposed to in series, but up until a certain point it actually makes much more sense to execute work in series, again, because of the expensive context switch. Pop quiz: If you have a thread that is doing a lot of computational work and using the CPU heavily, and this takes a while, should you switch to another thread? No! The current thread is efficiently using the CPU, so switching will only incur the cost of a context switch. Ok, well, what if you have a thread that makes an HTTP or SOAP request to another server and takes a long time, should you switch threads? Yes! You can perform the HTTP or SOAP request asynchronously, so that once the "send" has occurred, you can unwind the current thread and not use any threads until there is an I/O completion for the "receive". Between the "send" and the "receive", the remote server is busy, so locally you don't need to be blocking on a thread, but instead make use of the asynchronous APIs provided in .NET Framework so that you can unwind and be notified upon completion. Again, it only makes sense to switch threads if the benefit from doing so out weights the cost of the switch. Read more about it in these posts: Performing Asynchronous Work, or Tasks, in ASP.NET Applications http://blogs.msdn.com/tmarq/archive/2010/04/14/performing-asynchronous-work-or-tasks-in-asp-net-applications.aspx ASP.NET Thread Usage on IIS 7.0 and 6.0 http://blogs.msdn.com/tmarq/archive/2007/07/21/asp-net-thread-usage-on-iis-7-0-and-6-0.aspx   PS: I generally do not write posts that simply link to other posts but think it is warranted in this case.

    Read the article

  • Looking for an explanation of the 'Asynchronous' word in .Net?

    - by IbrarMumtaz
    I need someone to explain the following names; Asynchronous Delegates. Asynchronous methods. Asynchronous events. I'm currently going over this for my 70-536 exam and I am covering all my bases so far. The threading chapter and online resources have been good to me on my second read through. Still though, the names used above mean absolutely nothing to me? I would really appreciate the meaning behind the word 'Asynchronous' and its relevance to Delegates, methods and events. Feel free to go into as much detail as you like. Thanks, Ibrar

    Read the article

  • How do you plan your asynchronous code?

    - by NullOrEmpty
    I created a library that is a invoker for a web service somewhere else. The library exposes asynchronous methods, since web service calls are a good candidate for that matter. At the beginning everything was just fine, I had methods with easy to understand operations in a CRUD fashion, since the library is a kind of repository. But then business logic started to become complex, and some of the procedures involves the chaining of many of these asynchronous operations, sometimes with different paths depending on the result value, etc.. etc.. Suddenly, everything is very messy, to stop the execution in a break point it is not very helpful, to find out what is going on or where in the process timeline have you stopped become a pain... Development becomes less quick, less agile, and to catch those bugs that happens once in a 1000 times becomes a hell. From the technical point, a repository that exposes asynchronous methods looked like a good idea, because some persistence layers could have delays, and you can use the async approach to do the most of your hardware. But from the functional point of view, things became very complex, and considering those procedures where a dozen of different calls were needed... I don't know the real value of the improvement. After read about TPL for a while, it looked like a good idea for managing tasks, but in the moment you have to combine them and start to reuse existing functionality, things become very messy. I have had a good experience using it for very concrete scenarios, but bad experience using them broadly. How do you work asynchronously? Do you use it always? Or just for long running processes? Thanks.

    Read the article

  • Quality Design for Asynchronous WCF Services Calls in a Middle-Tier and Returning Data to UI Tier

    - by Perplexed
    I have a WPF application with a group of asynchronous WCF service calls all mashed into the code behind, complete with event handlers and everything, that I have to refactor to productionize and maintain. I want to separate concerns here for maintainability and all the other good reasons to do this, but I'm not sure exactly how to achieve this. Anybody have any good ideas on how to do this, or at least some links to put me in the right direction? My thinking: Create an "infrastructure" layer and reference the services there. Move the asynchronous event handlers into this layer. When an update is called, I will bubble up my own event with my own derivation of the EventArgs class that contains the data the UI will need. I'll have a fairly coupled hooking of the UI to the infrastructure layer as it will consume events I fire off upon completion of an asynchronous data call.

    Read the article

  • What are the differences in performance between synchronous and asynchronous JavaScript script loading?

    - by jasdeepkhalsa
    My question is simply: what are the differences in performance between synchronous and asynchronous JavaScript script loading? From what I've gathered synchronous code blocks the loading of a page and/or rest of the code from executing. This happens at two levels. First, at the level of the script actually loading, and secondly, within the JavaScript code itself. For example, on the page: Synchronous: <script src="demo_async.js" type="text/javascript"></script> Asynchronous: <script async src="demo_async.js" type="text/javascript"></script> And within a script: Synchronous: function a() {alert("a"); function b() {alert("b");}} Asynchronous (and self-executing): (function(a, function(b){ alert(b); }) { alert(a); }))(); So what really is the difference in performance from using these different loading methods and JavaScript patterns?

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >