<?xml version="1.0" encoding="ISO-8859-1"?>

<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/">
	<channel>
		<title>Alteryx Forums - Modules</title>
		<link>http://srcgroup.extendthereach.com</link>
		<description>Modules</description>
		<language>en</language>
		<lastBuildDate>Thu, 09 Sep 2010 17:39:28 GMT</lastBuildDate>
		<generator>vBulletin</generator>
		<ttl>60</ttl>
		<image>
			<url>http://srcgroup.extendthereach.com/images/misc/rss.jpg</url>
			<title>Alteryx Forums - Modules</title>
			<link>http://srcgroup.extendthereach.com</link>
		</image>
		<item>
			<title>Cancelling a module running via the api</title>
			<link>http://srcgroup.extendthereach.com/showthread.php?t=1406&amp;goto=newpost</link>
			<pubDate>Tue, 07 Sep 2010 16:05:19 GMT</pubDate>
			<description>I have a custom application which runs Alteryx modules using the api.  I need to add the ability to cancel a job which is running.  My first attempt...</description>
			<content:encoded><![CDATA[<div>I have a custom application which runs Alteryx modules using the api.  I need to add the ability to cancel a job which is running.  My first attempt works, but it takes a while for the module to stop.  Has anybody done anything similar or could offer any advice on where I am going wrong?<br />
<br />
The below code snippet shows how my current methodology works. (It is nicely tabbed on my machine but the forum seems to have removed them all...)<br />
<br />
The module c:\TestModule.yxmd takes 1:45 hours to run via the gui.<br />
<br />
using System;<br />
using System.Collections.Generic;<br />
using System.Linq;<br />
using System.Text;<br />
using System.Threading;<br />
using System.Runtime.InteropServices;<br />
<br />
namespace CancelJob<br />
{<br />
    class Program<br />
    {<br />
        static void Main(string[] args)<br />
        {<br />
            Module TestModule = new Module(@&quot;c:\TestModule.yxmd&quot;);<br />
            Thread RunModuleThread = new Thread(new ThreadStart(TestModule.Run));<br />
            Console.WriteLine(DateTime.Now.ToString() +  &quot; Starting Thread&quot;);<br />
            RunModuleThread.Start();<br />
            Thread.Sleep(5000);<br />
            Console.WriteLine(DateTime.Now.ToString() +  &quot; Aborting Thread&quot;);<br />
            RunModuleThread.Abort();<br />
            <br />
            while (RunModuleThread.ThreadState != ThreadState.Aborted &amp;&amp; RunModuleThread.ThreadState != ThreadState.Stopped)<br />
            {<br />
            }<br />
            Console.WriteLine(DateTime.Now.ToString() +  &quot; Thread Aborted&quot;);<br />
            Console.ReadKey();<br />
        }<br />
    }<br />
<br />
    class Module<br />
    {<br />
        string Path;<br />
<br />
        public Module(string _Path)<br />
        {<br />
            Path = _Path;<br />
        }<br />
<br />
        public void Run()<br />
        {<br />
            try<br />
            {<br />
                Alteryx.AlteryxApi.CallbackMessage pCallbackMessage = new Alteryx.AlteryxApi.CallbackMessage(this.CallbackMe  ssage);<br />
                Alteryx.AlteryxApi.AlteryxRunModule2(Path, null, null, pCallbackMessage, 0);<br />
                                <br />
            }<br />
            catch (ThreadAbortException err)<br />
            {<br />
                Console.WriteLine(DateTime.Now.ToString() + &quot; ThreadAbortException caught&quot;);<br />
                <br />
            }<br />
            catch<br />
            {<br />
                <br />
            }<br />
        }<br />
<br />
        private int CallbackMessage(System.Int64 userData, System.Int32 nToolId, Alteryx.AlteryxApi.E_CallbackStatus nStatus, [MarshalAs(UnmanagedType.LPWStr)]string pMessage)<br />
        {<br />
            return 0;<br />
        }<br />
    }<br />
<br />
}<br />
<br />
The above code produces this:<br />
<br />
07/09/2010 08:30:45 Starting Thread<br />
07/09/2010 08:30:50 Aborting Thread<br />
07/09/2010 09:02:00 ThreadAbortException caught<br />
07/09/2010 09:02:00 Thread Aborted<br />
<br />
So it's taking about half an hour for the thread to abort.  Next stage I'm thinking of looking at is the other api method for running jobs, but thought I would see if anyone here had any ideas first.<br />
<br />
Thanks<br />
Adam</div>

]]></content:encoded>
			<category domain="http://srcgroup.extendthereach.com/forumdisplay.php?f=31">Modules</category>
			<dc:creator>Adam Riley</dc:creator>
			<guid isPermaLink="true">http://srcgroup.extendthereach.com/showthread.php?t=1406</guid>
		</item>
	</channel>
</rss>
