w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
SynchronizationContext default behavior in TAP (Task Async Pattern)
First off, the article you referenced is talking about BackgroundWorker and not async. BackgroundWorker still works the same way in .NET 4.5, and still has the limitation around nested calls. For a description of how async works with SynchronizationContext, you can look at the end of that article or read my intro on async. In short, when an await is encountered, by default it will capture the current SynchronizationContext (or if it's null, the current TaskScheduler), and use that to schedule the continuation.

Categories : C#

rake default task how find source files?
Rails default rake tasks has all the rails default rake files rake -P lists all the rake tasks

Categories : Ruby On Rails

Azure Video Upload Task is getting failed @"My PlayReady Task" Error: MediaProcessor : An exception occurred during the execution of the task
What playready license server are you using ? From code perspective everything seems to be looking good. Since playready protection preset has not be included in sample, i assume it looks similar to example in following article: http://msdn.microsoft.com/en-us/library/windowsazure/dn189154.aspx Please make sure that value in licenseAquisitionURL is accessible from public network and your keySeedValue, or a keyID and a contentKey are still valid.

Categories : Azure

Why does task wait for Task.Run before executing next code but not for Task.Factory.StartNew?
I'm too not comfortable with all this plumbing but I'll try to answer. First why your second code does not work: you give StartNew an async delegate which is something like Func<Task> so StartNew will return a Task<Task> and you wait on the outer task which ends immediately as it consists in returning the inner Task (not really sure about that) then you await the continuation of the inner task, the inner thread of execution, what you intended to do; but I guess it should be the same if you awaited directly the inner task itself this way: await await Task.Factory.StartNew(async ... Why your first code works: according to the MSDN documentation Task.Run directly returns a Task object, the inner task I guess so you directly await for the inner task, not an intermediate one, so

Categories : C#

await Task.Factory.StartNew(() => versus Task.Start; await Task;
StartNew is just a short hand for creating and starting a task. If you want to do something to the Task instance before you start it, use the constructor. If you just want to create and start the task immediately, use the short hand. Documentation for StartNew says: Calling StartNew is functionally equivalent to creating a task by using one of its constructors, and then calling the Task.Start method to schedule the task for execution.

Categories : C#

Why Task.WhenAll throws TaskCanceledException and Task.WhenAny doesnt in the same test case
Task.WhenAny is designed to complete whenever one of the tasks completes, where completion includes failure. I actually find it most useful when one of the tasks might fail. For instance: try { await Task.WhenAny(task1,task2); cancellationToken.Cancel(); //cancel all tasks await Task.WhenAll(task1,task2); //wait for both tasks to respect the cancellation } catch (Exception x) { ... } Here I only need one of the tasks to complete (hence, the WhenAny). In which case I would like to cancel the other tasks as well. Then I call WhenAll to wait for the other task to respect the cancellation request, and also propagate an exception if it occurred. In other words, Task.WhenAny is designed to let you do something while other tasks are still running, and it is useful for it not to throw

Categories : Dotnet

Adjusting successor task dates in a database when predecessor task is edited
Very rudely, one solution is: In you database you should have the relation between tasks (usually an PARENT_ID column with a foreign key to the parent task) In your PHP code when you update one task you should validate if this task is PARENT of other task. If so, you need to update the child task(s). P.S. One idea to optimize PHP code may be getting all the tree of dependent tasks in one query instead of doing it recursively.

Categories : PHP

Is it possible to include modules in rake task and make its methods available for the task in rails app?
require 'modules/module_name' include ModuleName namespace :rake_name do desc "description of rake task" task example_task: :environment do result = ModuleName::method_name() end #end task end This works for me. Since your Module is not in /lib you might have to edit how it is required. But it should work. Hope it helps.

Categories : Ruby On Rails

How to start, pause, continue a task that executes every 5 seconds as a "keep busy" task
I suggest you make the problem much simpler. Have a recurring task which starts ever 5 seconds. the first thing does is check a volatile flag and if set, returns without doing anything. To turn this process, unset the flag. To pause it, set the flag. You task can do more than one thing. If it needs to do an R2 after T finishes, you can check for this and execute it in the same task. There is no need to create another task as such. Note: if you add R2 to the same ExecutorService as T, it has to wait for it to finish before it can start R2. This single threaded service can only do one thing at a time.

Categories : Java

how to check specific process (window task manager) is running or not using Windows Task Scheduler?
Okay! So you can take the approach as below using WMI and WIN32OLE require 'win32ole' wmi = WIN32OLE.connect("winmgmts://") processes = wmi.ExecQuery("select * from win32_process") ar = processes.each.with_object([]) {|i,a| a << i.name } # => ["System Idle Process", "System", "smss.exe", "csrss.exe",...] if ar.include? "rubyw.exe" #run a C:/test.rb file else # do nothing end

Categories : PHP

Silent exceptions in Task.Factory.StartNew when using a long running background consumer task?
Well, what are you assuming should happen instead? Are you thinking that whenever an exception is thrown in another thread it should immediately propagate to the thread that started that task? I strongly disagree. First off, the code in the calling thread would then be forced to abort the operation it's in the middle of, and that's rather likely to cause significant problems. Just look into all of the posts surrounding Thread.Abort to see all of the very significant problems that arise when you allow an exception to be thrown at some arbitrary point in a program's execution instead of at certain known points. If you're suggesting that the entire program should crash when a task's code throws an exception, then I'd say that by and large that's simply not desirable. In the rare case th

Categories : C#

celery task cannot open a model instance after passing a pk or id to the task after saving it in the django view
I had the same problem, try this @render_to('signup.html') def signup(request): if request.method == "POST": form = SignupForm(request.POST, request=request) if form.is_valid(): new_user = form.save(commit=False) new_user.email = form.cleaned_data["email"] new_user.fist_name = form.cleaned_data["first_name"] new_user.last_name = form.cleaned_data["last_name"] if new_user.save(): email_user_task.delay(new_user.pk) # this cannot get the User from the pk HttpResponseRedirect(reverse("signup_complete")) else: form = SignupForm(request=request) return locals()

Categories : Database

Define gradle task, to run task with specific system properties
Task.execute() should never be called from a build script (bad things can happen if you do). It's up to Gradle to call this method. The way to set system properties for the test task is: test { systemProperty "driver", "firefox" } System.setProperty() won't have any effect because tests always execute in a separate JVM.

Categories : Selenium

How to handle "End Task" from Windows Task Manager on a background process?
In general, when a process is listed as an "Application", it means Task Manger has detected the process has a GUI, and an "End Task" on a GUI will first attempt to graceful close the GUI via standard WM_CLOSE and/or WM_QUIT messages before then resorting to a brute-force termination of the GUI's process via TerminateProcess(). On the other hand, doing an "End Task" on a "Background Process" will perform a brute-force termination immediately. So in your situation, double-clicking on the .exe file results in a new dedicated console process that is running just your app by itself, so the console's GUI gets flagged as an "Application", but when you open a console window first and execute your .exe via the command-line, your app is running within the existing console and is sharing the conso

Categories : C++

Task.ContinueWith doesn't work after previous Task completed
Actually you setup continuation correctly, but you can't see result on console, because application exists before: Task<Int32> t = new Task<Int32>(n => Sum((Int32)n), 100); t.ContinueWith(tt => Console.WriteLine("Finished, SUM={0}", tt.Result), TaskContinuationOptions.OnlyOnRanToCompletion); t.ContinueWith(tt => Console.WriteLine("Exception thrown"), TaskContinuationOptions.OnlyOnFaulted); t.Start(); Console.ReadKey(); // keep app alive Application will not wait for background thread completion - it will be closed when main thread of application finishes it's work (your Main method) EDIT Another option is to wait until backround thread (continuation thread) completes and keep application alive: Task continuation = t.ContinueWi

Categories : C#

task in task scheduler failing when executing batch file
My workaround is to call a .BAT file from the Task Scheduler. This batch file then calls the PowerShell script file: powershell c:dir1AutoPopulate.ps1 Seems to work.

Categories : Batch File

Stop Continuation Task upon exception thrown from parent task
Don't swallow exception, and run continue only for not on faulted var parent = tf.StartNew(() => Parallel.ForEach(QuestionsLangConstants.questionLangs.Values, (i, state) => { try { qrepo.UploadQuestions(QWorkBook.Worksheets[i.QSheet], QWorkBook.Worksheets[i.QTranslationSheet], i, prog); } catch (Exception ex) { context.Dispose(); state.Break(); //make sure the execution fails throw; } })); var fi

Categories : C#

How do I pass an argument from a child task to a parent task in Rake
Not sure if you can set or pass a parameter, but you can use instance variables: task :first_task => :dep do puts "something else" puts @dir end task :dep do puts "something" @dir = "Foo" end Or just local variables: dir = "default_dir" task :first_task => :dep do puts "something else" puts dir end task :dep do puts "something" dir = "Foo" end For some kinds of task, it may make more sense to set environment variables: task :first_task => :dep do puts "something else" puts ENV['dir'] end task :dep do puts "something" ENV['dir'] = "Foo" end

Categories : Ruby On Rails

Structuring Task Processing Pipeline with the Task Parallel Library
I don't quite understand what you mean by completion callbacks not being an option due to having multiple tasks. Constructing a dataflow network for each task would mean the completion is triggered for them individually. I'm guessing you would want to avoid the overhead resulting from reconstructing the network each time? In that case, maybe you could add a passthrough block of sorts at the end: it returns whatever input it's given, and also calls whatever callback you need. So for each output produced by the network, the callback would be invoked. If you want to take it a step further, it could instead post a message to another block, which can then invoke the callbacks in parallel. Alternatively, if the pipeline is simple enough, and you don't need the extra buffering and whatnot, mayb

Categories : C#

The lack of non-capturing Task.Yield forces me to use Task.Run, why follow that?
You don't have to put the Task.Run in DoWorkAsync. Consider this option: public async Task UIAction() { // UI Thread Log("UIAction"); // start the CPU-bound work var cts = new CancellationTokenSource(5000); var workTask = Task.Run(() => DoWorkAsync(cts.Token)); // possibly await for some IO-bound work await Task.Delay(1000); Log("after Task.Delay"); // finally, get the result of the CPU-bound work int c = await workTask; Log("Result: {0}", c); } This results in code with much clearer intent. DoWorkAsync is a naturally synchronous method, so it has a synchronous signature. DoWorkAsync neither knows nor cares about the UI. The UIAction, which does care about the UI thread, pushes off the work onto a background thread using Task.Run. As

Categories : C#

Jake task firing complete before completion of async task
There seems to be a change of behaviour (not sure if it's bug or feature) between node 0.8 to 0.10. Jake tasks that were executing sequentially in 0.8.14 (with async:true) seem to start running concurrently in 0.10.x Try uninstalling node 0.10, and install 0.8 instead.

Categories : Javascript

Rx - How to create IObservable from Task such that unsubscribing cancels the task?
Here's the simplest way I can think of, using Observable.Create: static IObservable<int> SomeRxWork() { return Observable.Create<int>(o => { CancellationTokenSource cts = new CancellationTokenSource(); IDisposable sub = SomeAsyncWork(cts.Token).ToObservable().Subscribe(o); return new CompositeDisposable(sub, new CancellationDisposable(cts)); }); } static Task<int> SomeAsyncWork(CancellationToken token); The initial way I hinted at in the comments is actually rather verbose: static IObservable<int> SomeRxWork() { return Observable.Create<int>(async (o, token) => { try { o.OnNext(await SomeAsyncWork(token)); o.OnCompleted(); } catch (OperationCanceledEx

Categories : C#

In celery how to get the task status for all the tasks for specific task name?
This isn't natively supported. Depending on the backend (Mongo, Redis, etc), you may or may not be able to introspect the contents of a queue and find out what's in it. Even if you do, you'll miss items currently in progress. That said, you could manage this yourself: result = mytask.delay(...) my_datastore.save("mytask", result.id) ... for id in my_datastore.find(task="mytask"): res = AsyncResult(id) print res.state

Categories : Python

Task.WaitAll not throwing AggregateException while one of the task is still running
That's the expected behavior. If you hit the timeout before all the tasks have completed (either ran to completion, faulted, or cancelled), it will not throw the exception: it will just return false. It will only throw the exception in the case where all tasks have completed within the allotted time.

Categories : C#

Task Scheduler: run task each hour from the current moment
Ok, I've managed how to do almost I want by myself. For the Task Scheduler 2.0 it can be done by assigning another trigger to task: IRegistrationTask. If TASK_COMPATIBILITY_V1 setting will be set that trigger just wouldn't be assigned. For Windows XP I've just created IDailyTrigger with start boundary set to 00:05. That's not exactly what I need, but it works pretty well.

Categories : C++

Best way to code for Java 7 task required other task to finish first
CountdownLatch or a Phaser (if the number of preceding tasks can change).

Categories : Java

Gradle create multiple task types in one task
There is no zip method in Gradle. You can either use a task of type Zip (preferred), or use the Ant zip task. Also, you wouldn't typically go through a staging directory, but put contents into the zip right from their original locations. If necessary, you would declare another task that creates an exploded zip (and shares much of the Zip task's definition).

Categories : Gradle

Rx and tasks - cancel running task when new task is spawned?
Do you have to work with Tasks? If you're happy to work purely with Observables then you can do this nicely yourself. Try doing something like this: var query = Observable.Create<int>(o => { var cancelling = false; var cancel = Disposable.Create(() => { cancelling = true; }); var subscription = Observable.Start(() => { for (var i = 0; i < 100; i++) { Thread.Sleep(10); //1000 ms in total if (cancelling) { Console.WriteLine("Cancelled on {0}", i); return -1; } } Console.WriteLine("Done"); return 42; }).Subscribe(o); return new

Categories : C#

How to call a task in Task Scheduler from a Powershell script?
The simplest way may be to use schtasks.exe & schtasks.exe /Run /TN <Name of Scheduled Task> NOTE -- on my Windows 8.1 preview with PowerShell 4.0 there is a Start-ScheduledTask cmdlet.

Categories : Powershell

Connecting SQL task to data flow task programatically (c#)
Use STOCK:PipelineTask in place of DTS.Pipeline. Executables.Add() Method expect CLSID, PROGID, STOCK moniker, or CreationName property of the TaskInfo object. STOCK moniker is mostly used. DTS.Pipeline might not have recognized as any of them. If not using Stock Moniker, specify CLSID or PROGID equivalent to STOCK:PipelineTask.

Categories : C#

update task using Task Scheduler Managed Wrapper?
You can omit the UpdateFirstAction method. The library since version 1.6.1 has fixed the bug from that discussion item. The code is correct on how to edit the Path property. To update the task with the changed Path, you only need to call t.RegisterChanges() at the point you are calling UpdateFirstAction.

Categories : C#

Catching Exceptions of a Task that spawns an inner task
First chance exception messages most often do not mean there is a problem in the code. For applications / components which handle exceptions gracefully, first chance exception messages let the developer know that an exceptional situation was encountered and was handled. Please refer this

Categories : C#

Android: How to run a Task inside another Task (TimerTask)
try using yourview.post(new Runnable() { public void run() { //change your defined view here } }); inside timertask and update views inside the function above!

Categories : Android

How should I propagate task exception from continuation task in .NET 4.0?
If you're going to use asynchronous methods, then the whole method should be asynchronous and shouldn't block any threads. If you're not going to block, there is not much reason to use PLINQ, setting up the continuations from a single thread should be fast enough. If you want to continue when an exception happens, you will have to store the exceptions somewhere by yourself. I feel kind of uneasy about working with a collection of exceptions without throwing them, but I guess that's okay for an operation, that can partially fail and partially succeed. With that, my code for doing this would look like this: public Task<IEnumerable<Exception>> ExecuteOnServersAsync( IList<IEnumerable<Connection>> dbConnByServer, string sql, object parameters) { var task

Categories : C#

Better to use task dependencies or task.doLast in Gradle?
Whenever you can, model new activities as separate tasks. (In your case, you might add two more tasks.) This has many advantages: Better feedback as to which activity is currently executing or failed Ability to declare task inputs and outputs (reaping all benefits that come from this) Ability to reuse existing task types More possibilities for Gradle to execute tasks in parallel Etc. Sometimes it isn't easily possible to model an activity as a separate task. (One example is when it's necessary to post-process the outputs of an existing task in-place. Doing this in a separate task would result in the original task never being up-to-date on subsequent runs.) Only then the activity should be attached to an existing task with doLast.

Categories : Gradle

Celery, task called from other task is not working
Here's a simple example that I think accomplishes what you want. from celery import Celery import random import string celery = Celery('two_q',backend='amqp',broker='amqp://guest@localhost//') @celery.task def generate_rand_string(n): # n = number of characters rand_str = "".join([random.choice(string.lowercase) for i in range(n)]) #calls the second task and adds it to second queue reverse.apply_async((rand_str,),queue="q2") print rand_str return rand_str @celery.task def reverse(s): print s[::-1] return s[::-1] generate_rand_string.apply_async((10,), queue="q1") When called with the -Q argument which specifies the list of the queues celery worker --app=two_q -l info -Q q1,q2 it produces the following output: pawel@iqmxma82x7:~/py/celery$ celery

Categories : Python

Task.Yield() versus Task.Delay(0)
Inside Task.Delay, it looks like this (the single parameter (int) version just calls the below version): [__DynamicallyInvokable] public static Task Delay(int millisecondsDelay, CancellationToken cancellationToken) { if (millisecondsDelay < -1) { throw new ArgumentOutOfRangeException("millisecondsDelay", Environment.GetResourceString("Task_Delay_InvalidMillisecondsDelay")); } if (cancellationToken.IsCancellationRequested) { return FromCancellation(cancellationToken); } if (millisecondsDelay == 0) { return CompletedTask; } DelayPromise state = new DelayPromise(cancellationToken); if (cancellationToken.CanBeCanceled) { state.Registration = cancellationToken.InternalRegisterWithoutEC(delegate (object state) {

Categories : C#

Stop my task and all my waiting task
You need to design your routines to accept a CancellationToken, and then trigger a CancellationTokenSource.Cancel(). This will allow you to provide a mechanism to cooperatively cancel your work. For details, see Cancellation in Managed Threads and Task Cancellation on MSDN.

Categories : C#

Capistrano task from another task with parameters
Capistrano tasks can't really be parameterized. You can define a helper method, as follows: task :foo do bar(10) end def bar(n=variables[:n]) puts "N is #{n}" end If you're dead set on having :bar be a task as well, try this trick: task :foo do bar(10) end task :bar { bar } def bar(n=variables[:n]) puts "N is #{n}" end Note that the task MUST be declared before the method.

Categories : Ruby On Rails

Calling user variable inside another variable / SQL execute task / script task
You can set a variable based on another variable using expressions. The expression to determine the stored procedure would look something like: (@[User::BusinessProcess] == "Finance") ? "USP_Name1" : "USP_Name2" You can then set SQLStatementSource of an SQL Execute Task to the variable that contains the above expression. The same applies to destination. You can set the destination using an expression on your connection.

Categories : SQL



© Copyright 2017 w3hello.com Publishing Limited. All rights reserved.