Help with "owned" variables concept in WPF

I'm trying to move from WinForms to WPF and so far it's been going well. I'm struggling with the concept of updating variables from events in my code behind. It says that it was created or owned by another thread. Basically in my code all over the place I am
having to put:
this.Dispatcher.Invoke((Action)(() => { //Code Here }));
Generally this is happening from an async call to update some data.
Am I doing something fundamentally wrong in my design?
If this snippet of code is the solution, how do I understand without the runtime compiler telling me, when I should be doing it?
Can you explain what is happening with the Dispatcher.Invoke ((Action)(() =>{}));
My thinking so far
(Action) is casting the (() => {}) to an action object
() is creating a nameless function?
=> {} define the function right here, we could have pointed to a real function if we wanted.
Thanks for any education you can give me.

The thing is that you can only update a UI element on the thread on which it was created. This rule applies to both Windows Forms and WPF. Please refer to the following great article for more information about the threading model in WPF:
https://msdn.microsoft.com/en-us/magazine/cc163328.aspx. You should only create UI elements (TextBoxes, Buttons, etc.) on the UI thread and not on any background thread.
>>Can you explain what is happening with the Dispatcher.Invoke ((Action)(() =>{}));
The delegate (Action) that you pass to the Invoke method will be executed on the UI (or dispatcher) thread. Please refer to the above article for more information.
>>If this snippet of code is the solution, how do I understand without the runtime compiler telling me, when I should be doing it?
The Dispatcher has a CheckAccess() method that returns false if you are required to call the Invoke method, i.e. if the current thread doesn't have access to the UI object. You could just call this one before you call the Invoke method:
if (!Dispatcher.CheckAccess())
Dispatcher.Invoke(new Action(() => { }));
Hope that helps.
Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't post several questions in the same thread.

Similar Messages

  • Help with Report Variables

    I have been doing battle with the SBO Customer Receivables Aging Report. I am trying to add the fields "Customer Reference" and "Creation Date" to the Repetitive area of the report with no success. All of the existing fields are variables, and the on-line help says to contact SAP support (which would be me) for help with changing variables. Does anyne have a list of these variables, or know how to define them?
    Many thanks,
    Mike.

    Hi Mike Stroud, i'm actualy also working on the customer ageing report. You also responded to my post. It was the reports one. Well, im not sure about the variables but i simply wrote a query that brings all that info and more up. But i'm having problems diplsying it. In the normal SAP report/print layout, if i  make the report based on the query it doesn't let me move the info from the repetitive area to the header....why.....can you get around this??? I then did it in the advanced layout but the first page is always wrong. What do you want to do with the variables?? what are you trying to achieve with the report because me and my coleagues have had a BIG problem with the ageing.

  • Help with bind variables

    Hello I'm new to .net and I'm trying to work with bind variables
    I keep getting the ORA-01036: illegal variable name/number error.
    here's my code, can somebody help me out and show me what am I doing wrong?
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    Dim drLocation As OracleDataReader = getSCLocation("SOMEBODY")
    End Sub
    Private Function getSCLocation(ByVal contactName As String) As OracleDataReader
    Dim drLocation As OracleDataReader
    Dim connString As String = ConfigurationManager.ConnectionStrings("scConnString").ConnectionString
    Dim conn As New OracleConnection(connString)
    conn.Open()
    Dim queryString As String = "select a.location, a.location_name from locationm1 a where a.primary_contact_dept in (select b.dept from contactsm1 b where b.contact_name = p_contactName)"
    Dim p_contactName As New OracleParameter
    p_contactName.OracleType = OracleType.VarChar
    p_contactName.Value = contactName
    Dim cmdLocation As New OracleCommand(queryString, conn)
    cmdLocation.Parameters.Add(p_contactName)
    drLocation = cmdLocation.ExecuteReader(CommandBehavior.CloseConnection)
    Return drLocation
    End Function
    Thanks
    Peter

    never mind i got it by playing around with it
    had to change the way to start the bind variable
    Dim p_contactName As New OracleParameter("p_contactName", OracleType.VarChar)
    p_contactName.Size = 140
    p_contactName.Value = contactName

  • Help with ynamic variable evaluation

    Hi guys,
    If someone can point me out to how to evaluate variables as
    part of an expression.
    for ex:
    event.result.reporting.series[0].eval("y"+j+"Label");
    basically how do i write the equivalent of eval in
    flex/actionscript
    Thanks a ton,
    Pranay

    Thanks Greg, saved my day................
    1 more question
    Problem:
    My flex httpservice returns an xml file in the "object"
    resultFormat.
    How could I get the count of all childNodes of an object in
    that returned object tree.
    For example, in the xml file below:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <reporting>
    <series>
    <title>Edge Page Views, in Page Views per
    Second</title>
    <xLabel>startdatetime</xLabel>
    <y1Label>sum(pageviews)</y1Label>
    <data>
    <x>1216233600</x>
    <y1>79.605</y1>
    </data>
    <data>
    <x>1216233900</x>
    <y1>78.076</y1>
    </data>
    </series>
    <series>
    <title>Total Bandwidth, in Mbits per
    Second</title>
    <xLabel>startdatetime</xLabel>
    <y1Label>sum(egress_bytes_mbps)</y1Label>
    <y2Label>combined_midgress_bytes_mbps</y2Label>
    <y3Label>ovh_bytes_mbps</y3Label>
    <y4Label>sum(ingress_bytes_mbps)</y4Label>
    <data>
    <x>1216233600</x>
    <y1>36.160352</y1>
    <y2>66.48362700000001</y2>
    <y3>66.48362700000001</y3>
    <y4>96.01235200000002</y4>
    </data>
    <data>
    <x>1216233900</x>
    <y1>34.260794</y1>
    <y2>62.10649799999999</y2>
    <y3>62.10649799999999</y3>
    <y4>88.902323</y4>
    </data>
    <data>
    <x>1216234200</x>
    <y1>35.329617</y1>
    <y2>62.77339099999999</y2>
    <y3>62.77339099999999</y3>
    <y4>89.30751</y4>
    </data>
    </series>
    </reporting>
    The first series element has 4 children
    I am able to get the number of data elements as:
    "resultObj.reporting.series[0].data.length"
    How do I effectively retreive:
    "resultObj.reporting.series[0].childNodes().length"
    Apparently this does'nt work, I also tried Nodes, children().
    Any documentation or help with this would be awesome
    Thanks a ton
    Pranay

  • Need help with accesing variable with xpath.

    Hi All,
    I need help with xpath in "Switch" BPEL construct. Switch is used to compare value assigned to output vairable and follow one path for "Deny" and another for "Approve". The following is data type for output variable.
    <element name="processResponse">
         <complexType>
              <sequence>
                   <element name="result" type="string"/>
              <sequence>
         <complexType>
    </element>
    The following expressions in Switch statement throw lava.lang.Exception. It error is xpath internal error".
    x20:compare('Deny',$outputvariable.payload/client:result)
    x20:compare('Deny',bpws:getVariableData('outputvariable','payload','/client:processResponse/client:result')
    It works with x20:compare('Deny','Deny'). So I assumed it must be accessing the variable.
    Any help greatly appreciated.
    Thanks,
    Satish

    Cany you try the following
    x20:compare('Deny',string($outputvariable.payload/client:result))
    x20:compare('Deny',string(bpws:getVariableData('outputvariable','payload','/client:processResponse/client:result'))
    Regards
    Albin I
    http://www.albinsblog.com/

  • Please help with Load Variables / ASP

    Hello,
    I am using Load Variables to retreive a variable from an ASP
    page, (which uses a response.write) to output the variable
    getfile.onRelease = function()
    myData = new LoadVars();
    myData.onLoad = function(success){
    if(success) {
    getfile_txt.text = this.strString;
    } else {
    getfile_txt.text = "error";
    myData.load("sendFile.asp");
    stop();
    the problem is that the output says "undefined", but when I
    access the .asp page through my web browser I get the expected
    result of the variable which is "Test1.Doc"
    if any1 can help with this, i would be massivley thankful,
    thanks.

    p.s strString is the variable that I am trying to pass from
    the ASP page.

  • Need help with maintaining variable choices in new session

    I have a flash app. set up with several variables. Is there a
    simple action script that will allow the user to maintain their
    choices after closing the .swf and re-launching it?
    Thanks in advance for your help.

    how are you checking if those components have been checked or
    ticked. actually, i probably don't want to know that.
    you really should be using a listener to detect when your
    components have changed and then you can use the changed method to
    set your variables and update your sharedobject.

  • A little bit of help with Bind variables please

    Hi,
    I am having a bit of trouble with bind variables I have been looking at the Dev guide and the forum to try and achieve this and it is still not happening for me, could anybody please help or point me in the right direction:
    I have created a simple PersonVO with the basic query:
    Select distinct full_name from xxml_people where person_id = :1
    In the PersonVOImpl.java I have added the method:
    public void initQuery(String personId)
    Number person = null;
    try
    person = new Number(personId);
    catch
    (Exception e){}
    setWhereClauseParam(1,person);
    executeQuery();
    Then in the PersonAM I have added the method:
    public void initPersonQuery(String personId)
    getPersonVO1().initQuery(personId);
    I then call this method in my processRequest section of my page controller:
    PersonAMImpl am = (PersonAMImpl) pageContext.getRootApplicationModule();
    String personId = "581";
    am.initPersonQuery(personId);
    When I try and run this I get the error:
    oracle.apps.fnd.framework.OAException: oracle.jbo.SQLStmtException: JBO-27122: SQL error during statement preparation. Statement: SELECT distinct full_name from xxml_absence_calendar where person_id = :1
    java.sql.SQLException: ORA-01006: bind variable does not exist
    Am I binding the variables correctly? Or am I making some stupid mistake?
    I am ultimately looking to create a messageChoice where the logged in user will see a list of all organisations underneath him and the one level above. I plan to do this by passing the User’s Organisation name into a VO query using the organisation as a Bind Variable. I think once I have worked out how to bind variables this should be straight forward.
    Many Thanks

    Even though the parameter binding values may be same, you should never use the positional param more than once. So always go for the format
    select distinct full_name from xxml_people where supervisor_id = :1
    UNION
    select distinct full_name from xxml_people where person_id = :2
    --Shiv                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Help with object oriented concepts

    I am a senior highschool student and although I know Java syntax, I learned with Pascal and other procedural languages so I have a difficult time thinking in OOP concepts (which I will have to learn for college classes). So for practice I went to my college's website and found an assignment on the intro course to programming: [Here are the assignment instructions.|http://www.cs.gsu.edu/knguyen/teaching/2009/spring/csc2010/proj.pdf]
    My question is, how can I make my program illustrate more object oriented concepts?
    Links:
    ode-help.110mb.com/javaproject.java_

    Just a few comments (not necessarily about OO and in no particular order):
    It's probably not worth it to make constants for the letter A or the plus sign. Make constants for values people would not understand:
    // Ok
    public static final int ANSWER_TO_THE_UNIVERSE = 42;'
    // Probably overkill
    public static final int FORTY_TWO = 42;
    Good job on having DecimalFormat as a regular instance variable rather than static (since it is not thread-safe)
    Good job initializing your object in a consistent state (via the ctor). Now, make as many variables final as you can. Immutable objects are good:[www.javapractices.com/topic/TopicAction.do?Id=29]
    Not sure why you declared repeat() to return the boxed version of boolean, just use a primitive
    You have a run() method but are not implementing Runnable. Not that it is required, but usually when I see run(), I think of threading
    This is a matter of style, but you don't need to name the arguments in the ctor differently than the instance variables that get assigned. You can very easily say:
    // Note that it is final.  Make things immutable when you can.
    private final String bar;
    public Foo(final String bar) {
       // Note:  I don't need a different name here.  This is purely a matter of personal style.
       this.bar = bar;
    Consider a while loop in run() rather than a do-loop. What happens if you get no input the first time around?
    Java naming conventions dictate that classes start with a capital letter. Generally, an underscore is not used, camel-case is. So, your class should be JavaProject.
    Consider making an object for the arguments that are passed into input. Maybe call it GradeCategory, or whatever.
    That new object GradeCategory can have the output() method.
    For method names, also follow conventions using camel case. So get_double should be getDouble().
    Consider reworking such that you use an array or a collection of GradeCategory. You might want to then have an add method in your JavaProject. The add method should ensure the total weight of grades does not exceed 100%.
    You can rework the output method of JavaProject to iterate over your GradeCategory objects, calling their own output() methods. Perhaps it also first checks that the weight of all grades equals 100%.Just a few thoughts.
    - Saish

  • Help with multiple variable

    I'm trying to write a query which pulls shipment information
    from an access database. Then it grabs the weight of each shipments
    and multiplies it by the corresponding rate depending on its weight
    class.
    I'm using the CFIF, CFELSEIF and CFSET tags to try to
    accopmlisht this, making it look something like this
    <CFIF "Shipments.weight" LT 500 >
    <cfset Shipments.rate = 7.5 >
    <CFELSEIF "Shipments.weight" GT 499 LT 1000 >
    <cfset Shipments.rate = 7 >
    <CFELSEIF "Shipments.weight" GT 999 LT 2000 >
    <cfset Shipments.rate = 6.5 >
    <CFELSEIF "Shipments.weight" GT 1999 LT 5000 >
    <cfset Shipments.rate = 5 >
    <CFELSEIF "Shipments.weight" GT 4999 >
    <cfset Shipments.rate = 3.65 >
    </CFIF>
    then in the Output tag I use this CFSCRIPT
    <cfscript>
    WriteOutput(#ACC_Report.weight#/100*#Shipments.rate#);
    </cfscript>
    It runs fine but it only seems to grab either the first or
    the second set rate variables and multiplies all the weights in the
    output query by it, inetead of logically choosing its weight class.
    Any help, perhaps I'm using the wrong logic.
    Thanks in advance

    "There's no such thing as "greater-than-ness" on string data"
    Adam, everything you said is basically true and relevant to
    the original
    poster's issue. But this line is wrong is it not? Isn't
    comparing one
    string to another and determining which is greater or lesser
    the essence
    of sorting a set of strings into an alphabetical order?
    Now, I am not sure I can remember the last time I had to
    write my own
    sort routine. But I am pretty sure when I did for sorting
    string data,
    I communally compared one to another to see which was greater
    and|or
    lesser then the other.
    To reiterate in the original post, the person is comparing
    the string
    constants "Shipments.weight" to the numbers do to the
    improper quotes,
    not the value in the Shipments.weight variable.
    Also, if one cares, the logic could be greatly simplified
    with some
    basic boolean logic. The lower range comparisons are
    unnecessary.
    <CFIF Shipments.weight LT 500 >
    <!--- weight is less then 500 --->
    <cfset Shipments.rate = 7.5 >
    <CFELSEIF Shipments.weight LT 1000 >
    <!--- weight is greater then equal to 500 it was not
    caught in first
    branch, but it is also less then 1000 --->
    <cfset Shipments.rate = 7 >
    <CFELSEIF Shipments.weight LT 2000 >
    <!--- weight is greater then equal to 1000 it was not
    caught in any
    previous branch, but it is also less then 2000--->
    <cfset Shipments.rate = 6.5 >
    <CFELSEIF Shipments.weight LT 5000 >
    <!--- weight is greater then equal to 2000 it was not
    caught in any
    previous branch, but it is also less then 5000--->
    <cfset Shipments.rate = 5 >
    <CFELSE>
    <!--- weight is greater then equal to 5000 it was not
    caught in any
    previous branch--->
    <cfset Shipments.rate = 3.65 >
    </CFIF>

  • Help with bind variable

    I am very new to this site so I hope I get the format right...
    I am using Oracle Application Express Edition and trying to answer a question for my class, but I keep getting the same error every time. I've looked it up and it's apparently a storage error, but I don't understand how it can be a storage error if I'm not able to store it in the first place. So confused! Please help!
    Here's my code and the error I keep getting:
    DECLARE
    VARIABLE b_basic number
    VARIABLE b_pf number
    today DATE:=SYSDATE;
    tomorrow today%TYPE;
    BEGIN
    b_basic:=45;
    b_pf:=12;
    tomorrow:=today +1;
    DBMS_OUTPUT.PUT_LINE(' Hello World ');
    DBMS_OUTPUT.PUT_LINE('TODAY IS : '|| today);
    DBMS_OUTPUT.PUT_LINE('TOMORROW IS : ' || tomorrow);
    END;
    ORA-06550: line 2, column 23: PLS-00103: Encountered the symbol "NUMBER" when expecting one of the following: := . ( @ % ; not null range default character
    --------------------------------------------------------------------------------

    Don't mix SQL*Plus and PL/SQL syntax. In PL/SQL there is no VARIABLE keyword, just remove it.
    See http://docs.oracle.com/cd/E11882_01/appdev.112/e25519/fundamentals.htm#LNPLS208.
    With this:
    set echo on
    set serveroutput on
    DECLARE
    b_basic number;
    b_pf number;
    today DATE:=SYSDATE;
    tomorrow today%TYPE;
    BEGIN
    b_basic:=45;
    b_pf:=12;
    tomorrow:=today +1;
    DBMS_OUTPUT.PUT_LINE(' Hello World ');
    DBMS_OUTPUT.PUT_LINE('TODAY IS : '|| today);
    DBMS_OUTPUT.PUT_LINE('TOMORROW IS : ' || tomorrow);
    END;
    /you get with SQL*Plus command line:
    SQL> set serveroutput on
    SQL> --
    SQL> DECLARE
      2  b_basic number;
      3  b_pf number;
      4  today DATE:=SYSDATE;
      5  tomorrow today%TYPE;
      6  BEGIN
      7  b_basic:=45;
      8  b_pf:=12;
      9  tomorrow:=today +1;
    10  DBMS_OUTPUT.PUT_LINE(' Hello World ');
    11  DBMS_OUTPUT.PUT_LINE('TODAY IS : '|| today);
    12  DBMS_OUTPUT.PUT_LINE('TOMORROW IS : ' || tomorrow);
    13  END;
    14  /
    Hello World
    TODAY IS : 05-FEB-13
    TOMORROW IS : 06-FEB-13
    PL/SQL procedure successfully completed.Try to post APEX specific questions in APEX dedicated forum Oracle Application Express (APEX)
    Edited by: P. Forstmann on 5 févr. 2013 13:38
    Edited by: P. Forstmann on 5 févr. 2013 13:40

  • Need help with a variable

    I ahve a report that I want to show Free to Sell stock - stock that is in the warehouse that hasn't been allocated.
    I have created a variable called Freestock which basically uses a Physical Stock quantity minus the allocated stock quantity. 
    It is currently just adding all the figures together, instead of splitting it by item, so this is wrong
    Here's the formula I'm using ;
    =Sum(<Warehouse Physical Quantity>-<Outstanding Allocated Quantity>)
    Any help would be greatly appreciated in getting this sorted
    Thanks in advance

    George,
    I am sure the formula is correct.
    It is currently just adding all the figures together, instead of splitting it by item,
    You need to pull this variable with the item object. it will automatically break the number by the Item.
    Hope this helps.
    Kashif

  • Help with CLASSPATH variable please

    Hi everyone!!
    Please, help to set up my classpath variable. I know I know I have guidelines in API but I don't achieve it, I'm so clumsy.
    I've formated my hard disk and installed everything again, but the classpath is wrong because I can't compile my java files.
    I've tried with this:
    C:\Program Files\Java\jdk1.5.0_06\scr.zip;C:\Program Files\Java\jdk1.5.0_06\javac.exe;C:\Program Files\Java\jdk1.5.0_06\java.exe
    I've also tried with the same lines but unnaming files (finishing with '\')
    What am I doing wrong?
    Thank you very much for your attention and help.
    Merry Christmas and Happy New Year!!
    And I hope the Three Wise Men bring you everything!!

    Please post your exact problem and the exact error message. I think you are having a problem compiling, but I am not sure. What is not working? What is the error?
    You posted a path, but if that is your Classpath, you should not have javac or java in the Classpath.

  • Help with using variable for name of table in PLSQL block...

    I am trying to use a variable for the name of a table but getting errors ...i am sure I am close to the correct form here but something is wrong. I sure would appreciate some help!
    DECLARE
    ln_month Number;
    ln_day Number;
    ln_year Number;
    ls_year VarChar2(4);
    ls_prev_table VarChar2(30);
    ls_cur_table VarChar2(30);
    ln_prev_year Number;
    ls_prev_year VarChar2(4);
    ln_prev_month Number;
    BEGIN
    Select To_Number(To_Char(sysdate, 'MM')) into ln_month from dual;
    Select To_Number(To_Char(sysdate, 'DD')) into ln_day from dual;
    Select To_Number(To_Char(sysdate, 'YYYY')) into ln_year from dual;
    If ln_month = 01 Then
    ls_cur_table := "T_CPRS_FDW_CUR_JAN_ACTUALS";
    ls_prev_table := "T_CPRS_FDW_PREV_DEC_ACTUALS";
    ln_prev_year := ln_year - 1;
    /***above is where I am trying to use variables for assignement to years and months tables***//// ln_prev_month := 12;
    End If;
    /*------MORE IF STATEMENTS FOR EACH MONTH ---OF --THE YEAR ...AND its the following 2 variable statements that the compiler doesnt like! */
    If ln_day < 20 Then
    Delete from :ls_prev_table;
    INSERT INTO :ls_prev_table /*(STUFF TO BE INSERTED GOES HERE)*/
    HELP PLEASE!
    null

    Hi,
    The parser does not under variables directly in dml statements.u need to form a statement and the parse and execute the same...
    so the soln is
    Declare
    lv_stmt varchar2(250);
    Begin
    lv_stmt := 'Delete from '&#0124; &#0124;ls_prev_table;
    execute immediate lv_stmt;
    -- Same is the case with the insert stmt--
    End;
    This should solve ur problem.
    u could also give a direct call like
    execute immediate 'Delete from '&#0124; &#0124;ls_prev_table ;
    Note: This statement "execute immediate" holds good for oracle versions 8.x and above which makes the stmt very simple. For lower version u need to use the dbms_sql package to parse and execute the statement which has a series of statements for the same.
    Kiran

  • Newbie needs help with passing variables or creating flash object based on parameters

    Hello Community,
    I'm an amateur developer of Ms Access databases. In one of my applications I want to visualize the options available when reaching a certain score.
    What I'd like to get from this trial period, is a flash animation of a dartboard. Depending on an array of variables that provides the fill color (or reference thereof) the layers of the flash object will be dynamicly created, altered, or switched. The dartboard itself remains "static". I'm hoping to use 9 colors.
    I can manipulate the array any way needed. I can provide XML coding to pass the array variables. I'm just too new and untrained to incorporate this in a Edge animation or Dreamweaver.
    There is no need for interaction, once the object is created (ie no user feedback).
    Can someone point me in the right direction?
    thanks in advance,
    Jay from Stockholm

    Hi,
    I see you're using System.Data.OracleClient (which has been deprecated by MS) rather than Oracle.DataAccess.Client, but this works for me with Oracle's ODP, maybe it will help.
    Cheers,
    Greg
    using System;
    using System.Data;
    using Oracle.DataAccess.Client;
    using Oracle.DataAccess.Types;
    public class dataadapterfill
        public static void Main()
            using(OracleConnection con = new OracleConnection("user id=scott;password=tiger;data source=orcl"))
                con.Open();
                using(OracleCommand cmd = new OracleCommand("select ename from emp where ename = :1", con))
                    cmd.Parameters.Add(new OracleParameter("myename", OracleDbType.Varchar2, 50)).Value = "KING";
                    OracleDataAdapter da = new OracleDataAdapter(cmd);
                    DataSet ds = new DataSet();
                    da.Fill(ds);
                    foreach (DataRow row in ds.Tables[0].Rows)
                        Console.WriteLine("ename: {0}", row["ename"]);
    }

Maybe you are looking for