コード例 #1
0
 public RVList <LNode> ProcessFileWithThreadAbort(InputOutput io, Action <InputOutput> onProcessed, TimeSpan timeout)
 {
     if (timeout == TimeSpan.Zero || timeout == TimeSpan.MaxValue)
     {
         return(ProcessFile(io, onProcessed));
     }
     else
     {
         Exception ex     = null;
         var       thread = new ThreadEx(() =>
         {
             try { ProcessFile(io, null); }
             catch (Exception e) { ex = e; ex.PreserveStackTrace(); }
         });
         thread.Start();
         if (thread.Join(timeout))
         {
             onProcessed(io);
         }
         else
         {
             io.Output = new RVList <LNode>(F.Id("processing_thread_timed_out"));
             thread.Abort();
             thread.Join(timeout);
         }
         if (ex != null)
         {
             throw ex;
         }
         return(io.Output);
     }
 }
コード例 #2
0
        public void ZeroCodeLengthZipFile()
        {
            Assert.Throws <SharpZipBaseException>(() => {
                Exception threadException = null;
                var testThread            = new Thread(() => {
                    try {
                        var fileBytes = Convert.FromBase64String(TestFileZeroCodeLength);
                        using (var ms = new MemoryStream(fileBytes))
                            using (var zip = new ZipInputStream(ms))
                            {
                                while (zip.GetNextEntry() != null)
                                {
                                }
                            }
                    }
                    catch (Exception x) {
                        threadException = x;
                    }
                });

                testThread.Start();

                if (!testThread.Join(5000))
                {
                    // Aborting threads is deprecated in .NET Core, but if we don't do this,
                    // the poor CI will hang for 2 hours upon running this test
                    ThreadEx.Abort(testThread);
                    throw new TimeoutException("Timed out waiting for GetNextEntry() to return");
                }
                else if (threadException != null)
                {
                    throw threadException;
                }
            });
        }