Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. AsyncCallback problem?

AsyncCallback problem?

Scheduled Pinned Locked Moved C#
helpxmlquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Benny_Lava
    wrote on last edited by
    #1

    Hi, I have a method which is in another project (but in the same solution), I create a delegate to that method and then use delegate.BeginInvoke to Asynchronously call that method and the callback method is in the calling project. Now the problem is when the invoked method completes, I need to somehow signal the callback method if the invoked method has succedded True or False, and because the invoked method is in another project and the calling method is also in another project and this project has a reference to the invoked method project if I try to set some variable in the calling project from invoked method project I can't because i don't have a reference to this project and if I try to reference the project i get a circular dependency error.. which is resonable... This is the code:

    private delegate void edi2xml_delegate(object ar);
    private edi2xml_delegate edi2xml_del;

    public void convert_file(object async)
    {
    DemoApplication.edi_test edi2xml_converter = new DemoApplication.edi_test();
    edi2xml_converter.file_path = pub.def.edi_file_directory + "\\" + file_list.file_name;

       edi2xml\_del = new edi2xml\_delegate(edi2xml\_converter.convert);
    
       //--This is the invoking
       edi2xml\_del.BeginInvoke(null, import\_xml2db, (string)(pub.def.edi\_file\_directory + "\\\\" + file\_list.file\_name + ".xml"));
    

    }

    private void import_xml2db(IAsyncResult ar)
    {
    //--In this callback method i need to get the return state of the invoked method
    string full_path = (string)ar.AsyncState;

       edi2xml\_del.EndInvoke(ar);  
    

    }

    //--This function is in another project (another assembly) so I can't set some bool variable in the other project because i would get circular dependency error

    public void edi2xml()

    {
    //--Here I need to somehow signal the import_xml2db method(the callback method) that i have succeded or not (true-false)

    }

    Any help or suggestions greatly appreciated.

    L 1 Reply Last reply
    0
    • B Benny_Lava

      Hi, I have a method which is in another project (but in the same solution), I create a delegate to that method and then use delegate.BeginInvoke to Asynchronously call that method and the callback method is in the calling project. Now the problem is when the invoked method completes, I need to somehow signal the callback method if the invoked method has succedded True or False, and because the invoked method is in another project and the calling method is also in another project and this project has a reference to the invoked method project if I try to set some variable in the calling project from invoked method project I can't because i don't have a reference to this project and if I try to reference the project i get a circular dependency error.. which is resonable... This is the code:

      private delegate void edi2xml_delegate(object ar);
      private edi2xml_delegate edi2xml_del;

      public void convert_file(object async)
      {
      DemoApplication.edi_test edi2xml_converter = new DemoApplication.edi_test();
      edi2xml_converter.file_path = pub.def.edi_file_directory + "\\" + file_list.file_name;

         edi2xml\_del = new edi2xml\_delegate(edi2xml\_converter.convert);
      
         //--This is the invoking
         edi2xml\_del.BeginInvoke(null, import\_xml2db, (string)(pub.def.edi\_file\_directory + "\\\\" + file\_list.file\_name + ".xml"));
      

      }

      private void import_xml2db(IAsyncResult ar)
      {
      //--In this callback method i need to get the return state of the invoked method
      string full_path = (string)ar.AsyncState;

         edi2xml\_del.EndInvoke(ar);  
      

      }

      //--This function is in another project (another assembly) so I can't set some bool variable in the other project because i would get circular dependency error

      public void edi2xml()

      {
      //--Here I need to somehow signal the import_xml2db method(the callback method) that i have succeded or not (true-false)

      }

      Any help or suggestions greatly appreciated.

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Hi, I suggest you have a look at BeginInvoke, EndInvoke and IAsyncResult. This trio normally manages to synchronize with and obtain return values from asynchronous operations. :)

      Luc Pattyn [Forum Guidelines] [My Articles]


      The quality and detail of your question reflects on the effectiveness of the help you are likely to get. Show formatted code inside PRE tags, and give clear symptoms when describing a problem.


      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups