Search Results

Search found 11086 results on 444 pages for 'asynchronous pages'.

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

  • Pattern for limiting number of simultaneous asynchronous calls

    - by hitch
    I need to retrieve multiple objects from an external system. The external system supports multiple simultaneous requests (i.e. threads), but it is possible to flood the external system - therefore I want to be able to retrieve multiple objects asynchronously, but I want to be able to throttle the number of simultaneous async requests. i.e. I need to retrieve 100 items, but don't want to be retrieving more than 25 of them at once. When each request of the 25 completes, I want to trigger another retrieval, and once they are all complete I want to return all of the results in the order they were requested (i.e. there is no point returning the results until the entire call is returned). Are there any recommended patterns for this sort of thing? Would something like this be appropriate (pseudocode, obviously)? private List<externalSystemObjects> returnedObjects = new List<externalSystemObjects>; public List<externalSystemObjects> GetObjects(List<string> ids) { int callCount = 0; int maxCallCount = 25; WaitHandle[] handles; foreach(id in itemIds to get) { if(callCount < maxCallCount) { WaitHandle handle = executeCall(id, callback); addWaitHandleToWaitArray(handle) } else { int returnedCallId = WaitHandle.WaitAny(handles); removeReturnedCallFromWaitHandles(handles); } } WaitHandle.WaitAll(handles); return returnedObjects; } public void callback(object result) { returnedObjects.Add(result); }

    Read the article

  • How to TDD Asynchronous Events?

    - by Padu Merloti
    The fundamental question is how do I create a unit test that needs to call a method, wait for an event to happen on the tested class and then call another method (the one that we actually want to test)? Here's the scenario if you have time to read further: I'm developing an application that has to control a piece of hardware. In order to avoid dependency from hardware availability, when I create my object I specify that we are running in test mode. When that happens, the class that is being tested creates the appropriate driver hierarchy (in this case a thin mock layer of hardware drivers). Imagine that the class in question is an Elevator and I want to test the method that gives me the floor number that the elevator is. Here is how my fictitious test looks like right now: [TestMethod] public void TestGetCurrentFloor() { var elevator = new Elevator(Elevator.Environment.Offline); elevator.ElevatorArrivedOnFloor += TestElevatorArrived; elevator.GoToFloor(5); //Here's where I'm getting lost... I could block //until TestElevatorArrived gives me a signal, but //I'm not sure it's the best way int floor = elevator.GetCurrentFloor(); Assert.AreEqual(floor, 5); } Edit: Thanks for all the answers. This is how I ended up implementing it: [TestMethod] public void TestGetCurrentFloor() { var elevator = new Elevator(Elevator.Environment.Offline); elevator.ElevatorArrivedOnFloor += (s, e) => { Monitor.Pulse(this); }; lock (this) { elevator.GoToFloor(5); if (!Monitor.Wait(this, Timeout)) Assert.Fail("Elevator did not reach destination in time"); int floor = elevator.GetCurrentFloor(); Assert.AreEqual(floor, 5); } }

    Read the article

  • Waiting on multiple asynchronous calls to complete before continuing

    - by Chad
    So, I have a page that loads and through jquery.get makes several requests to populate drop downs with their values. $(function() { LoadCategories($('#Category')); LoadPositions($('#Position')); LoadDepartments($('#Department')); LoadContact(); }; It then calls LoadContact(); Which does another call, and when it returns it populates all the fields on the form. The problem is that often, the dropdowns aren't all populated, and thus, it can't set them to the correct value. What I need to be able to do, is somehow have LoadContact only execute once the other methods are complete and callbacks done executing. But, I don't want to have to put a bunch of flags in the end of the drop down population callbacks, that I then check, and have to have a recursive setTimeout call checking, prior to calling LoadContact(); Is there something in jQuery that allows me to say, "Execute this, when all of these are done."?

    Read the article

  • How to block the UI during asynchronous operations in WPF

    - by mcintyre321
    We have a WPF app (actually a VSTO WPF app). On certain controls there are multiple elements which, when clicked, load data from a web service and update the UI. Right now, we carry out these web requests synchronously, blocking the UI thread until the response comes back. This prevents the user clicking around the app while the data is loading, potentially putting it into an invalid state to handle the data when it is returned. Of course the app becomes unresponsive if the request takes a long time. Ideally, we'd like to have the cancel button active during this time, but nothing else. Is there a clever way of doing this, or will we have to switch the requests to execute asynchronously using backgroundworker and write something that disables all the controls apart from the cancel button while a request is in progress?

    Read the article

  • Adding dynamic controls to Silverlight application after WCF Service Asynchronous Callback

    - by Birk
    I'm trying to add some dynamic controls to my Silverlight page after a WCF call. When I try to add a control to I get an error: Object reference not set to an instance of an object. Here is a simplified version of my code: using edm = SilverlightBusinessApplication.ServiceRefrence; public partial class ListWCF : Page { edm.ServiceClient EdmClient = new ServiceClient(); public ListWCF() { EdmClient.GetTestCompleted += EdmGetTestCompleted; EdmClient.GetTestAsync(); } private void EdmGetTestCompleted(object sender, edm.GetTestCompletedEventArgs e) { //This is where I want to add my controls Button b = new Button(); LayoutRoot.Children.Add(b); //Error: Object reference not set to an instance of an object } } Is it not possible to modify the page after it has been loaded? What am I missing? Thanks

    Read the article

  • Javascript Detect All Images (Including Asynchronous)

    - by Zach
    Is there a way in javascript to detect all images in a document, including those that may be loaded asynchronously (and maybe after the DOM is ready)? I'm looking to create a function that can detect if Google Analytics has been loaded by searching through the DOM looking for "__utm.gif". document.images doesn't seem to hold this image as it's loaded asynchronously and not displayed.

    Read the article

  • 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

  • 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

  • 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

  • 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

  • Creating xaml 'template' for multiple pages

    - by superexsl
    Hey, I'm developing a Silverlight application for the first time. I've gone through some tutorials, but I can't seem to find anything that helps me with this particular problem. I would like a set of buttons to be present on all of my pages (like a template). When a button is pressed, I would like the ContentGrid to slide out and a new ContentGrid slide in (with the relevant .xaml file being loaded). Are there any tutorials showing the best way to do this? From samples I've seen, they only seem to transition between two pages, so copy-pasting the group of buttons on each xaml page isn't too much of a problem. However, with more pages, it would be inefficient to copy-paste the base layout each time. Thanks for any suggestions

    Read the article

  • How to get rid of blank pages in PDF exported from SSRS

    - by brijit
    Hi, I have a SSRS report. When i tried to export to PDF it was taking 4 pages due to its width., where the 2nd and 4th pages were displaying one of my field from the table. So i tried to set the layout size in report properties as width=18in and height =8.5in. It gave me the whole table in a single page of PDF. But I am getting 2nd and 4th page blank. Is the way I am doing is incorrect or else how to get rid of that blank pages. Please give some ideas. Thanks in advance. Brijit

    Read the article

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