.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

Arguments in BackgroundWorker

Posted By:      Posted Date: September 29, 2010    Points: 0   Category :Windows Application


I'm in need of a best solution. Situation is as follows: I intend to use BackgroundWorker to run database queries. Queries themselves require a diverse set of parameters collected (strings, dates, integers, arrays...) from the windows form of some sort. So far I have thousands of forms and twice as much SQL query methods in my solution and I have to make a coding standard for my team on how to implement the backgroundworker efficiently on those forms. So, the question is how to deliver those arguments to a worker thread while maintaining ease of maintenance and readability.

Bundling them to object[] array and pushing them trough an e.Argument reference is not very good solution, for example. It would work but if I have 20something parameters, using them is a coding nightmare (ie. (DateTime?)args[16]) not to mention what it takes if a want to remove a parameter or how to handle null values (we always use int?, DateTime?...).

Any suggestion is appreciated. Thanks.


View Complete Post

More Related Resource Links

More Versioning Fun With Optional Arguments

In my last blog post , I covered some challenges with versioning methods that differ only by optional parameters. If you haven't read it, go read it. If I do say so myself, it's kind of interesting. ;) In this post, I want to cover another very subtle versioning issue with using optional parameters. At the very end of that last post, I made the following comment. By the way, you can add overloads that have additional required parameters. So in this way, you are in the same boat as before. However, this can lead to subtle bugs. Let's walk through a scenario. Imagine that some class library has the following method in version 1.0. public static void Foo( string s1, string s2, string s3 = "v1" ) { Console.WriteLine( "version 1"...(read more)

Versioning Issues With Optional Arguments

One nice new feature introduced in C# 4 is support for named and optional arguments . While these two features are often discussed together, they really are orthogonal concepts. Let's look at a quick example of these two concepts at work. Suppose we have a class with one method having the following signature. // v1 public static void Redirect( string url, string protocol = "http" ); This hypothetical library contains a single method that takes in two parameters, a required string url and an optional string protocol . The following shows the six possible ways this method can be called. HttpHelpers.Redirect( "http://haacked.com/" ); HttpHelpers.Redirect(url: "http://haacked.com/" ); HttpHelpers.Redirect( "http...(read more)

How to Post Code To Your Blog and other Religious Arguments

If you've got a programming blog, chances are you'll want to post some code snippets. Posting code sounds easy but it's surprisingly tricky if you consider all the ways that people will be reading your blog. There's a number of ways. Here's a few and their pros and cons . Copy Paste from your IDE (like Visual Studio, for example) If I copy paste directly from VS into my editor of choice, Windows Live Writer, I'll get a <pre> section. using System; namespace WindowsGame1 { #if WINDOWS || XBOX     static class Program     {         /// <summary>         /// The main entry point for the application.        ...(read more)

Process.Start - arguments length restriction to 2080 characters

Hi, I'm wondering why is there a limit to "The sum of the length of the arguments and the length of the full path to the process " to 2080? I see that the documentation says that a Win32Exception is thrown if this exceeds 2080 characters. Can someone please explain to me this limit? I'm trying to start a process and I have a lot of arguments to pass, and of course ... I exceed the limit of 2080.   Thanks, Ionut.

The best overloaded method match for... has some invalid arguments

I have a compilation error generated by this scenario: i have : 1. DataAccessLayses 2. Entity 3. PresentationLayer(web application)4. BankServices(web service) inside the webservice i have one web method with argument of my pre-defined class library it name is CustomerEL and the class in PresentationLayer calling the webservice method ,CustomerEL cusE = new CustomerEL();objsv.addCustomer(cusE);(addCustomer(<argument>) is method in BankServices)  and here the eror occuredcan you help me !Regards

Enumerating Variables & Arguments in Rehosted Designer

I'm trying to enumerate the variables and arguments of a workflow after I load it into my rehosted designer.  I see that I can use ActivityMetadata.GetArgumentsWithReflection() and ActivityMetadata.GetVariablesWithReflection() but those require that I have ActivityMetadata to start with.  So the real question is, how do I get the ActivityMetadata once I've done MyWorkflowDesigner.Load(XamlPath);?Thanks in advance.ChuckChuck Berg | Consulting Engineer | Corporate IT - Station Casinos, Inc.

How to persist workflow with non-serializable arguments

I have a workflow that has some arguments for underlying components (DAL implementation, email sender etc). It also has a  WCF data contract and other serializable arguments. I need to persist and unload this workflow and then resume later on. It is throwing an exception because it is trying to serialize and persist all the workflow arguments. Is there a way to get the serializer to persist only those arguments that can be serialized?

Examining the context/arguments for an idle workflow

Short version: How can I get the values of arguments for an activity that's been idled?  That is, is there some way to load the activity up (without resuming it) so that I can retrieve the values of the arguments? Long version: I have an activity.  It takes in a large amount of information via its arguments, emails a user that they've got work to do, and then creates a bookmark and idles.  That part works fine. The user clicks the link in the email and goes to a page that presents to them information about the work they need to do.  This information comes from the arguments passed into the activity.  I'm missing the magic link that'll get me that information.  I could have the activity persist all of its arguments to the database, but this seems redundant (as the instance is already persisted to the database) and inefficient (I only need this information while the activity is idle).   What am I missing?

The values provided for the root activity's arguments did not satisfy the root activity's requirem

I have flowchart as implementation  of activitybuilder and added two dynamicactivityproperty to it. The flowchart is having flowdecision and 3 other customized activities with same defined arguments. But when i invoke the workflow and pass dictionary, it gives the error: The values provided for the root activity's arguments did not satisfy the root activity's requirements: 'Sample Workflow': The following keys from the input dictionary do not map to arguments and must be removed: FolderName, FolderSize.  Please note that argument names are case sensitive. Parameter name: rootArgumentValues Flowchart       fc = new Flowchart();  protected override void OnInitialized(EventArgs e) { wd.Load(new ActivityBuilder { Implementation =  fc});             ModelTreeManager mtm = wd.Context.Services.GetService<ModelTreeManager>();             ModelItem ab = mtm.Root;             ModelItemCollection argsAndProperties = ab.Properties["Properties"].Collection;                     InArgument<string> foldername = new InArgument<string>();    &n

arguments null in onSuccess method

HiI'm trying to validate user input into a textbox via a web service.I'm using a Dynamic Data site, with a custom Dynamic Data field to show this particular value. In the dynamic data field I've added a custom validator - <asp:CustomValidator id="CustomValidator1" runat="server"        ErrorMessage="Invalid Item ID!"      ControlToValidate="TextBox1"      OnServerValidate="ServerValidate"      ClientValidationFunction="validateItem"     /><asp:CustomValidator id="CustomValidator1" runat="server" ErrorMessage="Invalid Item ID!" ControlToValidate="TextBox1" OnServerValidate="ServerValidate" ClientValidationFunction="validateItem" />In a custom page, I have the following Javascript - <script type="text/javascript"> <!-- function validateItem(source, arguments) { InventTableService.exists(arguments.Value, onComplete, onError); } function onComplete(source, arguments) { alert(source); arguments.IsValid = source; }

Script Task w/C# & WMI - Passing Arguments

Hello All: I have a script task using WMI to remotely create a process that I need to pass arguments to (code below). I am getting outParams["returnValue"]) = 9. Thanks, Tom public void Main() { string remoteMachine = "remServer"; ConnectionOptions connOptions = new ConnectionOptions(); ManagementScope manScope = new ManagementScope(String.Format(@"\\{0}\ROOT\CIMV2", remoteMachine), connOptions); manScope.Connect(); ObjectGetOptions objectGetOptions = new ObjectGetOptions(); ManagementPath managementPath = new ManagementPath("Win32_Process"); ManagementClass processClass = new ManagementClass(manScope, managementPath, objectGetOptions); ManagementBaseObject inParams = processClass.GetMethodParameters("Create"); inParams["CurrentDirectory"] = @"E:\Program Files\7-zip"; inParams["CommandLine"] = @"7z.exe a -tzip E:\Data\MDP_76_01\Daily\arch.zip E:\Data\MDP_76_01\Daily\*"; ManagementBaseObject outParams = processClass.InvokeMethod("Create", inParams, null); Dts.TaskResult = (int)ScriptResults.Success; }

Retrieving out parameter/arguments from MethodInfo.Invoke

Hi everybody.For example, I have a method like this:public int DoSomething(int x, out int z){   z = x + 1;   return x + 2;}Then I invoke this method using MethodInfo.Invoke via reflection:MethodInfo myMethod = this.GetType().GetMethod("DoSomething");int result = myMethod.Invoke(this, new object[] { 5, 0 });The code working fine, I got the result = 7 (which is from x + 2).But how I can get the z ? (which is x + 1) ?Please advise,Thanks,Lok_Tan

SharePoint - Passing Dataview Row Arguments to a C# function from a button

RE: SharePoint - Passing Dataview Row infomration to a C# function I've done this with a asp.net Gridview. but does anybody have any examples on how to pass row information from an asp.net button in  SharePoint Dataview rows to an inline C# function? the button Repeats as follows: <asp:Button runat="server" Text="Delete" id="Delete{@ID}"  OnClick="DeleteDoc()"/> My function looks like this: void DeleteDoc(object sender, EventArgs e) { } I tried adding another parameter but get: No overload for 'DeleteDoc' matches delegate 'System.EventHandler' Thank you.

Webmethod backgroundworker freezes client

Hi guys,I am writing a webservice which has to perform a long running job. It is a requirement that I call the webmethod synchronously but the webmethod executes another method asynchronously and returns to the client. So I used a background worker on the webmethod to run and I call it asynchronously, then the method returns. Unfortunately the client still waits until the backgroundworker is completed.Below is a sample code to simulate the problem:using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Services;using System.ComponentModel;namespace BackgroundWorkerTest{    /// <summary>    /// Summary description for Service1    /// </summary>    [WebService(Namespace = "http://tempuri.org/")]    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]    [System.ComponentModel.ToolboxItem(false)]    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.     // [System.Web.Script.Services.ScriptService]    public class Service1 : System.Web.Services.WebService    {        BackgroundWorker bkgW = null;        [WebMethod]    &n

sp_MSadd_logreader-history has too many arguments specified code 1007

I installed a new sql 2005 server and set 4 publications with subscription. The replication is working but looks slow....It means when I change a value into a table the transaction take more than 30 secondes before it came into the synchronisation status monitor.   I saw that for each subscription my logreader agent could not start ...I have the following message.   MessageExecuted as user: 280db02\280db02sql. The replication agent encountered an error and is set to restart within the job step retry interval. See the previous job step history message or Replication Monitor for more information.     Message-XCMDLINE 0   -XCancelEventHandle 00000000000007B4   -XParentProcessHandle 00000000000003C82007-04-20 09:54:32.109 Parameter values obtained from agent profile:   -pollinginterval 5000   -historyverboselevel 1   -logintimeout 15   -querytimeout 1800   -readbatchsize 500   -readbatchsize 5000002007-04-20 09:54:32.109 Status: 4096, code: 20024, text: 'Initializing'.2007-04-20 09:54:32.109 The agent is running. Use Replication Monitor to view the details of this agent session.2007-04-20 09:54:32.125 Status: 16384, code: 20007, text: 'No replicated transactions are available.'.2007-04-20 09:55:37.125 Status: 16384, code: 20007, text: 'No replicated transactions are available.'.2007-04-20 09:55:37.125 Status: 0, code: 22037, text: 'The last step did not log any message!'.20

BackgroundWorker dont works starting an user control on MVVM



I have a problem using backgroundworker object.

If I use a code to load with Entity Framework a SQL table for fill a combobox, the program takes a lot of time and user experience is bad.
If I use a backgroundworker object, simply the combobox is'nt filled; my MVVM class that have a public property ObservableCollection<MyRecord>. I debug the code and this collection is filled right but WPF appears dont know that collection is recently filled. I try to use on Source property of combo the OneWay and TwoWay attributes, but dont work

I'm sure that any thing do it bad ¿Any body can tell me where try to fix up the problem?

    Private Sub LoadCountries()

'This code works fine, but user experience is affected
      'Me.Recursos = New ObservableCollection(Of Recurso)(Application.Contexto.Recursos.Include("User"))

      Using worker As New BackgroundWorker()

        Dim p As System.ComponentModel.DoWorkEventHandler =

Task vs. Backgroundworker



in .Net 4.0 there is a new "Task" class. Currently I'm using BackgroundWorkers for my background tasks. Should I use the new "Task" class instead? What are the benefits/drawbacks with the Task class?

Thanks for your help.



ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend