ä»åã¯ãSystem.IProgress
IProgress
æåéããé²æç¶æ³ãå¦çããããã®åã§ãã
IProgress
å©ç¨æ¹æ³ã¯ãã·ã³ãã«ã§
- ã³ã³ã¹ãã©ã¯ã¿ã«Actionããªã²ã¼ãã渡ãã¦æ§ç¯
- ProgressChangedã¤ãã³ãããã³ãã«
ãããã¨ã§ãå©ç¨ã§ãã¾ãã
å®éã«é²æãå¦çããã«ã¯ã
IProgress<T>.Report(T)
ã¡ã½ãããå¼ã³åºãã¾ãã
GUIã§ãå¥ã®å¦çãããªããç»é¢ã«é²æç¶æ³ãåºåããéã«å©ç¨ã§ãã¾ãã
Taskã¨CancellationTokenã¨Progress
以åããåå¨ãã¦ããBackgroundWorkerã¨åããããªäºãå®è£
ã§ãã¾ãã
Progress
SynchronizationContextããã£ããã£ãã¦ä¿æãã¾ããReportã¡ã½ããã
å
é¨ã§ã³ã¼ã«ããã¯ãå®è¡ããéã«ããã£ããã£ããSynchronizationContextä¸ã§
ãã®ã¡ã½ãããå®è¡ãã¦ããã¾ãããªã®ã§ããã®ã¡ã½ããã®ä¸ã§ã¯ãInvokeãªãã§UIè¦ç´ ã«ã¢ã¯ã»ã¹ãããã¨ãã§ãã¾ãã
ãªã®ã§ãProgress
UIã¹ã¬ããä¸ã§newãã¦ããªãã¨ããã£ããã£ãããSynchronizationContextãéããã®ã«ãªã£ã¦ãã¾ãã¾ãã
ãã®ãããã®äºæ
ã¯ãBackgroundWorkerã®å ´åã¨åãã§ããã
SynchronizationContextã«ã¤ãã¦ã¯ã以åã«è¨äºãã¢ãããã¦ãã¾ãã®ã§ãåç §ãã ããã
- .NET ã¯ã©ã¹ã©ã¤ãã©ãªæ¢è¨ª-018 (AsyncOperation, AsyncOperationManager, SynchronizationContext)(ã³ã³ããã¹ã,ã³ã³ããã¹ãã®åæ,éåæå¦ç)
- .NET ã¯ã©ã¹ã©ã¤ãã©ãªæ¢è¨ª-040 (System.Windows.Forms.WindowsFormsSynchronizationContext)(SynchronizationContext, åæã³ã³ããã¹ã, Send, Post)
以ä¸ãµã³ãã«ã§ãã
ãªããããããµã³ãã«ãæãã¤ããªãã£ãã®ã§ãã¨ããããããã°ã¬ã¹ãã¼ãæ´æ°ããã ãã®
ãã®ã¨ãªã£ã¦ãã¾ãããåå¼ãï½
å®è¡ããã¨ãããã°ã¬ã¹ãã¼ãæ´æ°ããã¦ä¼¸ã³ã¦ãããMAXã«ãªã£ããã¾ãå
ã«æ»ã伸ã³ã¦ããã
ç¹°ãè¿ãã¾ãããã ããCancellationTokenSourceãã¿ã¤ã ã¢ã¦ãä»ãã§è¨å®ãã¦ããã®ã§
è¨å®ããã¿ã¤ã ã¢ã¦ãæéãè¶
ããããèªåçã«ãã£ã³ã»ã«æ±ãã¨ãªããå¦çãçµäºãã¾ãã
ä¸è¨ãµã³ãã«ã®ä¸ã®
var progress = new Progress<int>(SetProgress); //var progress2 = Task.Run(() => new Progress<int>(SetProgress)).Result; await PerformStep(tokenSource.Token, progress);
ã¨ãªã£ã¦ããé¨åãã
//var progress = new Progress<int>(SetProgress); var progress2 = Task.Run(() => new Progress<int>(SetProgress)).Result; await PerformStep(tokenSource.Token, progress2);
ã«å¤ãã¦ãå®è¡ããã¨ä»åº¦ã¯ããã°ã¬ã¹ãã¼ãä¸å伸ã³ãªãããã«ãªãã¾ãã
Progress
ãDispatcherSynchronizationContextã¨ãªããªãããã§ãã(ãã®å ´åãThreadPoolã§å®è¡ããã¾ãã)
[追è¨]
ãªããããµã³ãã«ããã¾ãã«ãã·ã§ãã¤ã®ã§ãããä¸ã¤ä½ãã¾ããï½
ãã¡ããã·ã§ãã¤ã®ã§ãããã¡ãã£ã¨ãã·ããªã¨ã
以ä¸ã§ã¯ãã«ã¬ã³ããã©ã«ãã®å
容ãï¼ãã¡ã¤ã«ãã¤å§ç¸®ãã¦ãï¼ã¤ã®Zipãã¡ã¤ã«ãä½æãã¦ãã¾ãã
ãã®éã®é²æç¶æ³ã®å¦çã«Progress
å¦çéä¸ã§ãã£ã³ã»ã«ãããããç°¡æãã¼ã«ããã¯å¦çããã¦ãã¾ãã
ZipFileã¯ã©ã¹ã®æ¦è¦ã«ã¤ãã¦ã¯ã以ä¸ã®è¨äºããåç §ãã ããã
- .NET ã¯ã©ã¹ã©ã¤ãã©ãªæ¢è¨ª-062 (System.IO.Compression.ZipFile (1), .NET 4.5ãã追å , ZIPãã¡ã¤ã«ã®å§ç¸®/解å)
- .NET ã¯ã©ã¹ã©ã¤ãã©ãªæ¢è¨ª-063 (System.IO.Compression.ZipFile (2), .NET 4.5ãã追å , ZIPãã¡ã¤ã«å ã®ã¨ã³ããªãåæ, ZipArchive, ZipArchiveEntry)
- .NET ã¯ã©ã¹ã©ã¤ãã©ãªæ¢è¨ª-064 (System.IO.Compression.ZipFile (3), .NET 4.5ãã追å , ZIPãã¡ã¤ã«ãä½æããã³æ´æ°, CreateEntryFromFile, CreateEntry)
ãã®ã¾ã¾ã ã¨ãå¦çãããã«çµãã£ã¦ãã¾ãã®ã§ãããã¨Task.Delayãå ¥ãã¦ãã¾ãã
以ä¸ãåèè³æã§ããæ£ç´ãæ©æ¢°ç¿»è¨³ã®æ¥æ¬èªãè¥å¹²å¤ãªã®ã§åæèªãã æ¹ãããããããã¨æãã¾ãã
- IProgress
ã¤ã³ã¿ã¼ãã§ã¤ã¹ - Progress
ã¯ã©ã¹
ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼ï¼
éå»ã®è¨äºã«ã¤ãã¦ã¯ã以ä¸ã®ãã¼ã¸ãããåç
§ä¸ããã
- ããããåå¿é²æ¥è¨ã¾ã¨ã
ãµã³ãã«ã³ã¼ãã¯ã以ä¸ã®å ´æã§å ¬éãã¦ãã¾ãã
- ããããåå¿é²æ¥è¨ãµã³ãã«ã½ã¼ã¹ç½®ãå ´