Search Unity

How to get around the threading limit

Discussion in 'Windows' started by cygnusprojects, Jun 3, 2014.

  1. cygnusprojects

    cygnusprojects

    Joined:
    Mar 13, 2011
    Posts:
    767
    We created a chess game in which the actual engine is running on a separate thread. Everything works fine building the project for desktop, however building it for Windows Store results in the System.Threading namespace not being recognized. So I can build for a Windows 8(.1) desktop but can't sell it on the Windows Store ... hmmm.
    Anyone any idea on how to get around this limitation? Do I miss something?
    I already tried to change the engine to a coroutine approach but needless to say this is way too expensive as Unity and the chess engine are on the same thread.

    Edit: Error message when building for Windows Store: Assets\Scripts\Engine\ChessEngine.cs(325,13): error CS0103: The name 'ThreadPool' does not exist in the current context
     
    Last edited: Jun 3, 2014
  2. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
  3. cygnusprojects

    cygnusprojects

    Joined:
    Mar 13, 2011
    Posts:
    767
    I'm completely lost converting the project to Windows Store :(

    I'm using the following code (snippets):

    Code (CSharp):
    1. #if NETFX_CORE
    2.   using Windows.System.Threading;
    3. #else
    4.   using System.Threading;
    5. #endif
    at the start of the script and following code:
    Code (CSharp):
    1. #if !NETFX_CORE
    2.   myThinker = new Thread(new ThreadStart(Thinker));
    3.   myThinker.Start();
    4. #else
    5.   IAsyncAction asyncAction = Windows.System.Threading.ThreadPool.RunASync((workItem) =>
    6.   {
    7.   Thinker();
    8.   });
    9.   m_workItem = asyncAction;
    10. #endif
    but apparently I'm missing something but I can't pinpoint what exactly.

    However building the project results into the following errors:
    Assets\Scripts\Engine\ChessEngine.cs(328,13): error CS0246: The type or namespace name 'IAsyncAction' could not be found (are you missing a using directive or an assembly reference?)
    Assets\Scripts\Engine\ChessEngine.cs(328,76): error CS0117: 'Windows.System.Threading.ThreadPool' does not contain a definition for 'RunASync'

    I'm trying to follow the example Microsoft provides at http://msdn.microsoft.com/en-us/library/windows/apps/jj248677.aspx
     
  4. Tautvydas-Zilys

    Tautvydas-Zilys

    Unity Technologies

    Joined:
    Jul 25, 2013
    Posts:
    10,674
    Since IAsyncAction is in Windows.Foundation namespace, add "using Windows.Foundation;" under NETFX_CORE #ifdef.

    As for run async, you've got a typo:

    That it's RunAsync :).
     
  5. cygnusprojects

    cygnusprojects

    Joined:
    Mar 13, 2011
    Posts:
    767