<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Multitasking in Software Archive</title>
    <link>https://community.intel.com/t5/Software-Archive/Multitasking/m-p/942841#M17469</link>
    <description>Hi, &lt;BR /&gt; &lt;BR /&gt;There's another approach, which I deem purer: let the fortran code run &lt;BR /&gt;in a thread, and pass a few synchronization objects through its arg-list so &lt;BR /&gt;that it could change their state from time to time; in this way, the caller &lt;BR /&gt;remains running. However, you have to ensure that nothing harmful happens in the VB caller in the meantime, i.e. you have to disable GUI options which may affect the calculation (e.g. you probably wouldn't like &lt;BR /&gt;the user to run the same calculation again while one's already running). &lt;BR /&gt; &lt;BR /&gt;A simple but nice solution is to create a modal dialog box in VB caller with a progress bar (and, optionally, a "Cancel" button); that would enable the user _only_ to watch (or, possibly, cancel) the current operation, while VB window would remain normally painted. I mean something like this: &lt;BR /&gt; &lt;BR /&gt;&lt;PRE&gt; 
SUBROUTINE ProgressDialog_OnInitialize() 
 
!User-defined object for passing data 
TYPE T_SyncObj 
   INTEGER hProgressBar     !Handle of PB control 
   INTEGER hEvent               !Event used for cancelling 
END TYPE 
 
TYPE(T_SyncObj) SyncObj 
 
!TODO declare FortranCalc routine as appropriate; SyncObj 
!should be ByRef 
SyncObj%hProgressBar=GetDlgItem(hDialog, ID_PROGRESSBAR) 
SyncObj%hEvent=CreateEvent(NULL,.TRUE.,.FALSE.,NULL) 
hThread=CreateThread(NULL, 0, LOC(FortranCalc), LOC(SyncObj), 0, LOC(idThread)) 
 
END SUBROUTINE 
!============================= 
SUBROUTINE ProgressDialog_OnCancel() 
 
RaiseEvent(SyncObj%hEvent) 
EndDialog(hDialog) 
 
END SUBROUTINE 
!============================= 
INTEGER FUNCTION FortranCalc(SyncObj) 
!DEC$ATTRIBUTES STDCALL:: FortranCalc 
!DEC$ATTRIBUTES REFERENCE:: SyncObj 
 
TYPE(T_SyncObj)::   SyncObj 
 
DO i=1,many_iterations 
... 
     !Update progress bar 
     SendMessage(SyncObj%hProgressBar,PBM_STEPIT,0,0) 
     !Check if the user cancelled the operation 
     IF (WaitForSingleObject(SyncObj%hEvent,0).EQ.WAIT_OBJECT_0) THEN 
          FortranCalc=0 
          ResetEvent(SyncObj%hEvent) 
     END IF 
END DO 
FortranCalc=1 
 
END FUNCTION 
&lt;/PRE&gt; &lt;BR /&gt; &lt;BR /&gt;The code above is rather pseudo -- I'm not familiar with VB, but I hope you'll get the idea); of course, take care about the scope of type declarations. You can also put in T_SyncObj all parameters needed in arg-list. Take care that T_SyncObj is declared identical in VB and Fortran. Don't forget to CloseHandle(SyncObj%hEvent) after the dialog ends (I'm not sure if it's allowed to CloseHandle in FortranCalc). &lt;BR /&gt; &lt;BR /&gt;HTH &lt;BR /&gt; &lt;BR /&gt;Jugoslav</description>
    <pubDate>Thu, 15 Mar 2001 20:51:50 GMT</pubDate>
    <dc:creator>Jugoslav_Dujic</dc:creator>
    <dc:date>2001-03-15T20:51:50Z</dc:date>
    <item>
      <title>Multitasking</title>
      <link>https://community.intel.com/t5/Software-Archive/Multitasking/m-p/942838#M17466</link>
      <description>Trying to improve the cooperation between legacy code recast as CVF DLLs and the Visual Basic wrapper programs that use them.  Some of the DLLs run a very long time and thus keep Windows from servicing the message queue.  On older PCs (like my P133 dino), this locks up the PC for the duration of the run and makes updating status dialogs (in VB) difficult. &lt;BR /&gt; &lt;BR /&gt;Wondered if any of the forum users have any suggestions for preempting the DLL periodically, allowing the VB layer to update its status screens, and then resuming the DLL where it left off. &lt;BR /&gt; &lt;BR /&gt;Thanks</description>
      <pubDate>Thu, 15 Mar 2001 01:52:17 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Multitasking/m-p/942838#M17466</guid>
      <dc:creator>Intel_C_Intel</dc:creator>
      <dc:date>2001-03-15T01:52:17Z</dc:date>
    </item>
    <item>
      <title>Re: Multitasking</title>
      <link>https://community.intel.com/t5/Software-Archive/Multitasking/m-p/942839#M17467</link>
      <description>Usually, the way this is done is to periodically call back into VB, to a routine whose address you pass in, allowing VB to update the window, then return to the Fortran code.&lt;BR /&gt;&lt;BR /&gt;Steve</description>
      <pubDate>Thu, 15 Mar 2001 02:35:52 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Multitasking/m-p/942839#M17467</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2001-03-15T02:35:52Z</dc:date>
    </item>
    <item>
      <title>Re: Multitasking</title>
      <link>https://community.intel.com/t5/Software-Archive/Multitasking/m-p/942840#M17468</link>
      <description>Steve &lt;BR /&gt; &lt;BR /&gt;Thanks - I thought that was the way, but I'm still struggling with the mechanics.  Can you point me to a reasonably concise example of how CVF implements a callback - My approaches all seem to crash.  I looked at the MS BB Help files and they jumped right off to the deep end - way more complicated than anything I need. &lt;BR /&gt; &lt;BR /&gt;P.. &lt;BR /&gt; &lt;BR /&gt;Every time I try to reply to your posting, the forum software asks me to log in again and makes it look like I'm replying to my original posting.  I'll look later to see what's up there - probably I'm just not familiar with the new forum operation. &lt;BR /&gt; &lt;BR /&gt;Thanks</description>
      <pubDate>Thu, 15 Mar 2001 08:13:43 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Multitasking/m-p/942840#M17468</guid>
      <dc:creator>Intel_C_Intel</dc:creator>
      <dc:date>2001-03-15T08:13:43Z</dc:date>
    </item>
    <item>
      <title>Re: Multitasking</title>
      <link>https://community.intel.com/t5/Software-Archive/Multitasking/m-p/942841#M17469</link>
      <description>Hi, &lt;BR /&gt; &lt;BR /&gt;There's another approach, which I deem purer: let the fortran code run &lt;BR /&gt;in a thread, and pass a few synchronization objects through its arg-list so &lt;BR /&gt;that it could change their state from time to time; in this way, the caller &lt;BR /&gt;remains running. However, you have to ensure that nothing harmful happens in the VB caller in the meantime, i.e. you have to disable GUI options which may affect the calculation (e.g. you probably wouldn't like &lt;BR /&gt;the user to run the same calculation again while one's already running). &lt;BR /&gt; &lt;BR /&gt;A simple but nice solution is to create a modal dialog box in VB caller with a progress bar (and, optionally, a "Cancel" button); that would enable the user _only_ to watch (or, possibly, cancel) the current operation, while VB window would remain normally painted. I mean something like this: &lt;BR /&gt; &lt;BR /&gt;&lt;PRE&gt; 
SUBROUTINE ProgressDialog_OnInitialize() 
 
!User-defined object for passing data 
TYPE T_SyncObj 
   INTEGER hProgressBar     !Handle of PB control 
   INTEGER hEvent               !Event used for cancelling 
END TYPE 
 
TYPE(T_SyncObj) SyncObj 
 
!TODO declare FortranCalc routine as appropriate; SyncObj 
!should be ByRef 
SyncObj%hProgressBar=GetDlgItem(hDialog, ID_PROGRESSBAR) 
SyncObj%hEvent=CreateEvent(NULL,.TRUE.,.FALSE.,NULL) 
hThread=CreateThread(NULL, 0, LOC(FortranCalc), LOC(SyncObj), 0, LOC(idThread)) 
 
END SUBROUTINE 
!============================= 
SUBROUTINE ProgressDialog_OnCancel() 
 
RaiseEvent(SyncObj%hEvent) 
EndDialog(hDialog) 
 
END SUBROUTINE 
!============================= 
INTEGER FUNCTION FortranCalc(SyncObj) 
!DEC$ATTRIBUTES STDCALL:: FortranCalc 
!DEC$ATTRIBUTES REFERENCE:: SyncObj 
 
TYPE(T_SyncObj)::   SyncObj 
 
DO i=1,many_iterations 
... 
     !Update progress bar 
     SendMessage(SyncObj%hProgressBar,PBM_STEPIT,0,0) 
     !Check if the user cancelled the operation 
     IF (WaitForSingleObject(SyncObj%hEvent,0).EQ.WAIT_OBJECT_0) THEN 
          FortranCalc=0 
          ResetEvent(SyncObj%hEvent) 
     END IF 
END DO 
FortranCalc=1 
 
END FUNCTION 
&lt;/PRE&gt; &lt;BR /&gt; &lt;BR /&gt;The code above is rather pseudo -- I'm not familiar with VB, but I hope you'll get the idea); of course, take care about the scope of type declarations. You can also put in T_SyncObj all parameters needed in arg-list. Take care that T_SyncObj is declared identical in VB and Fortran. Don't forget to CloseHandle(SyncObj%hEvent) after the dialog ends (I'm not sure if it's allowed to CloseHandle in FortranCalc). &lt;BR /&gt; &lt;BR /&gt;HTH &lt;BR /&gt; &lt;BR /&gt;Jugoslav</description>
      <pubDate>Thu, 15 Mar 2001 20:51:50 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Multitasking/m-p/942841#M17469</guid>
      <dc:creator>Jugoslav_Dujic</dc:creator>
      <dc:date>2001-03-15T20:51:50Z</dc:date>
    </item>
    <item>
      <title>Re: Multitasking</title>
      <link>https://community.intel.com/t5/Software-Archive/Multitasking/m-p/942842#M17470</link>
      <description>...just to add, I forgot the obvious RETURN in the IF (WaitForSingleObject) block.</description>
      <pubDate>Thu, 15 Mar 2001 20:57:58 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Multitasking/m-p/942842#M17470</guid>
      <dc:creator>Jugoslav_Dujic</dc:creator>
      <dc:date>2001-03-15T20:57:58Z</dc:date>
    </item>
    <item>
      <title>Re: Multitasking</title>
      <link>https://community.intel.com/t5/Software-Archive/Multitasking/m-p/942843#M17471</link>
      <description>The forum will ask you to log in again if you haven't done anything in the last 15 minutes.  Annoying, I know.&lt;BR /&gt;&lt;BR /&gt;When you reply, it shows you the initial topic, but you can see all of the replies if you scroll up.  This message board is not threaded, so there is no concept of a "reply to a reply".&lt;BR /&gt;&lt;BR /&gt;Steve</description>
      <pubDate>Fri, 16 Mar 2001 01:07:14 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Multitasking/m-p/942843#M17471</guid>
      <dc:creator>Steven_L_Intel1</dc:creator>
      <dc:date>2001-03-16T01:07:14Z</dc:date>
    </item>
    <item>
      <title>Re: Multitasking</title>
      <link>https://community.intel.com/t5/Software-Archive/Multitasking/m-p/942844#M17472</link>
      <description>Since the original posting, I've belatedly found the sample "Callback" in SamplesB.  I plan to investigate that approach so the the BB front end can do the heavy lifting and I can keep Fort ran "engine" from becoming too Windows-specific. &lt;BR /&gt; &lt;BR /&gt;We are also planning to port our legacy code to NIX and Linux platforms, so whatever approach allows me to encapsulate the platform-specific stuff in an abstraction layer will probably be used.  The sample code from Samples and that from I_hunter and Yugoslav Dujic will be evaluated in that light.  When we settle on an approach, I'll try to remember to report it here. &lt;BR /&gt; &lt;BR /&gt;One question about the two approaches cited - Are they compatible with a DELL (required to interface with VB) or do they require building the project as a QWIN or Windows project?  I'll be able to answer this myself when I get back to the office - Don't have all of the tools here at home. &lt;BR /&gt; &lt;BR /&gt;Thanks again. &lt;BR /&gt; &lt;BR /&gt;Thanks to</description>
      <pubDate>Tue, 20 Mar 2001 00:44:38 GMT</pubDate>
      <guid>https://community.intel.com/t5/Software-Archive/Multitasking/m-p/942844#M17472</guid>
      <dc:creator>Intel_C_Intel</dc:creator>
      <dc:date>2001-03-20T00:44:38Z</dc:date>
    </item>
  </channel>
</rss>

