当前位置: 首页>>代码示例>>C#>>正文


C# IDispatcher.Execute方法代码示例

本文整理汇总了C#中IDispatcher.Execute方法的典型用法代码示例。如果您正苦于以下问题:C# IDispatcher.Execute方法的具体用法?C# IDispatcher.Execute怎么用?C# IDispatcher.Execute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IDispatcher的用法示例。


在下文中一共展示了IDispatcher.Execute方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: NotifyHashEnd

 private void NotifyHashEnd(IDispatcher dispatcher, HashProgress notifier)
 {
     if (notifier != null)
     {
         Action action = () => notifier(Path, 100);
         if (dispatcher != null)
         {
             dispatcher.Execute(action);
         }
         else
         {
             action();
         }
     }
 }
开发者ID:hoangduit,项目名称:ndupfinder,代码行数:15,代码来源:File.cs

示例2: CalculateHash

        private async Task CalculateHash(
            IDispatcher d,
            HashProgress notifier)
        {
            if (notifier != null)
            {
                Action action = () => notifier(Path, 0);
                if (d == null)
                {
                    action();
                }
                else
                {
                    d.Execute(action);
                }
            }

            //TODO - exception handling
            StorageFile file = await GetFromRoot(m_path, m_root);
            int num_chunks = (int) (GetSize()/Chunker.chunk_size) + 1;
            int hash_size = num_chunks*32;
            float current_chunk = 0;
            var hash_builder = new StringBuilder(hash_size);
            m_hash = "";

            var chunker = new Chunker(GetSize());

            foreach (Chunk chunk in chunker.GetChunks())
            {
                using (IRandomAccessStream inputStream = await file.OpenAsync(FileAccessMode.Read))
                {
                    using (var dataReader = new DataReader(inputStream.GetInputStreamAt(chunk.Start)))
                    {
                        await dataReader.LoadAsync(chunk.Length);
                        IBuffer buf = dataReader.ReadBuffer(chunk.Length);
                        IBuffer hashed = m_alg.HashData(buf);
                        hash_builder.Append(CryptographicBuffer.EncodeToHexString(hashed));
                    }
                }
                current_chunk++;


                if (notifier != null)
                {
                    float percent_done = current_chunk/num_chunks;
                    Action action = () => notifier(Path, percent_done*100);
                    if (d == null)
                    {
                        action();
                    }
                    else
                    {
                        d.Execute(action);
                    }
                }
            }

            m_hash = hash_builder.ToString();

            if (hash_size > 32) //hash the hash 
            {
                // Convert the string to UTF8 binary data.
                IBuffer hashbuf = CryptographicBuffer.ConvertStringToBinary(m_hash, BinaryStringEncoding.Utf8);
                IBuffer hashed = m_alg.HashData(hashbuf);
                m_hash = CryptographicBuffer.EncodeToHexString(hashed);
            }

            if (notifier != null)
            {
                Action action = () => notifier(Path, 100);
                if (d == null)
                {
                    action();
                }
                else
                {
                    d.Execute(action);
                }
            }
        }
开发者ID:hoangduit,项目名称:ndupfinder,代码行数:80,代码来源:File.cs

示例3: StartExecution

        /// <summary>
        /// Starts the execution.
        /// </summary>
        private void StartExecution()
        {
            pgBar.Value = 0;
            Boolean localEnabled = false, remoteEnabled = false;
            List<IRemoteGateClient> clients = new List<IRemoteGateClient>();

            /* Manually control the status of local machine */
            foreach (IServer server in m_WorkSpace.Servers)
            {
                if (server is LocalServer)
                {
                    if (server.Enabled)
                    {
                        server.Status = ServerStatus.Running;
                        localEnabled = true;
                    }
                }

                if (server is RemoteServer)
                {
                    if (server.Enabled)
                    {
                        RemoteServer rServer = (RemoteServer)server;

                        server.Status = ServerStatus.Down;
                        IRemoteGateClient newClient = null;

                        if (rServer.ConnectionType == ConnectionType.Http)
                        {
                            if (rServer.SecurityKey != null)
                                newClient = new HttpRemoteGateClient(rServer.Host, rServer.Port, rServer.SecurityKey, 1000);
                            else
                                newClient = new HttpRemoteGateClient(rServer.Host, rServer.Port, 1000);
                        }
                        else if (rServer.ConnectionType == ConnectionType.Tcp)
                        {
                            if (rServer.SecurityKey != null)
                                newClient = new TcpRemoteGateClient(rServer.Host, rServer.Port, rServer.SecurityKey, 1000);
                            else
                                newClient = new TcpRemoteGateClient(rServer.Host, rServer.Port, 1000);
                        }

                        newClient.ConnectedToServer += newClient_ConnectedToServer;
                        newClient.DisconnectedFromServer += newClient_DisconnectedFromServer;
                        rServer.Client = newClient;

                        clients.Add(newClient);
                        remoteEnabled = true;
                    }
                }
            }

            DispatchMode mode = DispatchMode.Combined;

            if (localEnabled && remoteEnabled)
                mode = DispatchMode.Combined;
            else if (localEnabled)
                mode = DispatchMode.LocalOnly;
            else if (remoteEnabled)
                mode = DispatchMode.RemoteOnly;

            UpdateAllNodes();

            /* Runtime creation of Generic type */
            Type dynamicDispatcher = typeof(Dispatcher<,,>).MakeGenericType(new Type[] { typeof(CSharpScriptAssembler), m_WorkSpace.LocalBalancer, m_WorkSpace.RemoteBalancer });

            m_Dispatcher = (IDispatcher)Activator.CreateInstance(dynamicDispatcher,
                new Object[] { m_WorkSpace.QueueSize,
                    (m_WorkSpace.NumberOfThreads == 0) ? Environment.ProcessorCount : m_WorkSpace.NumberOfThreads,
                    mode });

            m_Dispatcher.AlgorithmProgress += m_dispatcher_AlgorithmProgress;
            m_Dispatcher.AlgorithmComplete += m_dispatcher_AlgorithmComplete;

            /* Add remote hosts */
            foreach (IRemoteGateClient client in clients)
            {
                m_Dispatcher.RegisterGate(client);
            }

            m_AlgorithmInstance = m_WorkSpace.Provider.GetAlgorithmInstance();

            m_CurrentWorkValue = 0;
            m_LastWorkValue = 0;
            m_MaxWorkValue = 0;
            m_MeasurmentsDone = 0;
            m_AverageSpeed = 0;

            m_Finished = false;
            UpdateStatusLabel();

            graphView.AddLine(0, Color.Red).Thickness = 2;

            m_Dispatcher.Execute(m_AlgorithmInstance);
            pgBarTimer.Start();

            m_IsRunning = true;
//.........这里部分代码省略.........
开发者ID:pavkam,项目名称:school,代码行数:101,代码来源:DCalcForm.cs


注:本文中的IDispatcher.Execute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。