<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.infopathdev.com:443/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Data Connections</title><link>https://www.infopathdev.com:443/forums/44.aspx</link><description> </description><dc:language>en</dc:language><generator>CommunityServer 2007 SP3 (Build: 31118.962)</generator><item><title>Using Data Connections in a Separate Thread</title><link>https://www.infopathdev.com:443/forums/thread/100717.aspx</link><pubDate>Thu, 08 Jan 2015 15:52:40 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:100717</guid><dc:creator>Mark_H</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/100717.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=44&amp;PostID=100717</wfw:commentRss><description>&lt;p&gt;Hello there,&lt;/p&gt;&lt;p&gt;I&amp;#39;ve been struggling with this particular issue for a couple days now and I have had an awful time trying to find a confirmation that this should or should not work.&lt;/p&gt;&lt;p&gt;I am using the CAML method to submit data from an InfoPath 2013 form to various SharePoint lists. I also query data from those lists via a number of data connections I have setup in the InfoPath GUI. The requests over our VPN are taking a great deal of time whenever I open a data connection and query or submit data. I&amp;#39;m trying to improve the user experience by potentially executing the data connections in a separate thread. I am new to threading so I may just be making a simple mistake but I have been able to use threads successfully in a couple other simple scenarios.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;I have tried a number of threading methods but here is the current example of what I have setup:&lt;/p&gt;&lt;p&gt;I have a separate class I&amp;#39;m using to pass arguments to my separate thread which my current implementation uses a BackgroundWorker.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;(I declare a new FormCode member variable at the top of Form code that will hold the thread argument details)&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;i&gt;public ThreadedQueryInfo queryInfo = new ThreadedQueryInfo(); &lt;/i&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;In a subsequent method I create and call a BackgroundWorker:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;i&gt;_queryBW = new BackgroundWorker();&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;_queryBW.DoWork += _queryBW_StartQuery;&lt;/i&gt;&lt;/p&gt;&lt;p&gt;&lt;i&gt;_queryBW.RunWorkerAsync(queryInfo); &lt;/i&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Here is the method that gets executed by the&amp;nbsp; BackgroundWorker:&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;i&gt;private void _queryBW_StartQuery(object sender, DoWorkEventArgs e)&lt;br /&gt;{&lt;br /&gt;ThreadedQueryInfo info = (ThreadedQueryInfo)e.Argument;&lt;br /&gt;&lt;br /&gt;DataConnections[info.sharepointList].Execute();&lt;br /&gt;&lt;br /&gt;info.complete = true;&lt;br /&gt;} &lt;/i&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;When I attempt to execute this query, I am getting&amp;nbsp; the following exception: &lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&lt;i&gt;HResult=-2146233079&lt;br /&gt;&amp;nbsp; Message=&lt;b&gt;Operation is not valid due to the current state of the object.&lt;/b&gt;&lt;br /&gt;&amp;nbsp; Source=Microsoft.Office.InfoPath.Client.Internal.Host&lt;br /&gt;&amp;nbsp; StackTrace:&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; at Microsoft.Office.InfoPath.Internal.MomExceptionHelper.ExecuteDataConnectionAction(XmlFormHost formHost, OMCall d)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; at Microsoft.Office.InfoPath.Internal.SharePointListAdapterRWQueryAdapterHost.Execute()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; at Solution_Requests_IPForm_ver12.FormCode._queryBW_StartQuery(Object sender, DoWorkEventArgs e) in c:\...\...\Local\Temp\Vsta\505864c8d93a44e49f3de6eaa92cd0d5\FormCode.cs:line 840&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; at System.ComponentModel.BackgroundWorker.OnDoWork(DoWorkEventArgs e)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; at System.ComponentModel.BackgroundWorker.WorkerThreadStart(Object argument) &lt;/i&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;The Status attribute of the exception shows: System.Net.WebExceptionStatus.UnknownError and the Response shows: null.&lt;/p&gt;&lt;p&gt;I was looking around and noticed this article: &lt;a href="http://msdn.microsoft.com/en-us/library/office/aa948521%28v=office.15%29.aspx" title="http://msdn.microsoft.com/en-us/library/office/aa948521%28v=office.15%29.aspx"&gt;http://msdn.microsoft.com/en-us/library/office/aa948521%28v=office.15%29.aspx &lt;/a&gt;which mentions particular dll&amp;#39;s that may be a problem but I am not using the the ones mentioned.&lt;/p&gt;&lt;p&gt;I was wondering if anyone here might have some experience with executing data connections from another thread or know that it is not supported.&lt;/p&gt;&lt;p&gt;I apologize if I&amp;#39;ve left out any crucial information needed. Thank you in advance for your time! &lt;br /&gt;&lt;/p&gt;</description></item></channel></rss>