2011-04-07 215 views
0

为什么我的应用程序意外停止?我尝试了一切来解决错误,但我找不到解决方案。这是一个Windows应用程序。应用程序意外停止

UPDATE:

事件观看者:

Faulting application viamura.crawlerapp.exe, version 1.0.0.0, stamp 4d9d9be8, faulting module imon.dll, version 2.70.16.0, stamp 455c9b06, debug? 0, fault address 0x0002474a. 
Application: ViaMura.CrawlerApp.exe 
Framework Version: v4.0.30319 
Description: The process was terminated due to an unhandled exception. 
Exception Info: System.AccessViolationException 
Stack: 
    at System.Net.UnsafeNclNativeMethods+OSSOCK.recv(IntPtr, Byte*, Int32, System.Net.Sockets.SocketFlags) 
    at System.Net.Sockets.Socket.Receive(Byte[], Int32, Int32, System.Net.Sockets.SocketFlags, System.Net.Sockets.SocketError ByRef) 
    at System.Net.Sockets.Socket.Receive(Byte[], Int32, Int32, System.Net.Sockets.SocketFlags) 
    at System.Net.Sockets.NetworkStream.Read(Byte[], Int32, Int32) 
    at System.Net.PooledStream.Read(Byte[], Int32, Int32) 
    at System.Net.ConnectStream.ReadSingleByte() 
    at System.Net.StreamChunkBytes.get_NextByte() 
    at System.Net.ChunkParse.GetChunkSize(System.Net.IReadChunkBytes, Int32 ByRef) 
    at System.Net.ConnectStream.ProcessReadChunkedSize(System.Net.StreamChunkBytes) 
    at System.Net.ConnectStream.ReadChunkedCallbackWorker(System.Net.NestedSingleAsyncResult, System.Net.ConnectStream) 
    at System.Net.ConnectStream.ReadChunkedCallback(System.Object) 
    at System.Threading.QueueUserWorkItemCallback.WaitCallback_Context(System.Object) 
    at System.Threading.ExecutionContext.Run(System.Threading.ExecutionContext, System.Threading.ContextCallback, System.Object, Boolean) 
    at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem() 
    at System.Threading.ThreadPoolWorkQueue.Dispatch() 
    at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback() 


For more information, see Help and Support Center at 
EventType clr20r3, P1 viamura.crawlerapp.exe, P2 1.0.0.0, P3 4d9d9759, P4 viamura.crawlerapp, P5 1.0.0.0, P6 4d9d9759, P7 e, P8 36, P9 system.exception, P10 NIL. 

代码1:

try 
      { 
       Application.EnableVisualStyles(); 
       Application.SetCompatibleTextRenderingDefault(false); 
       Application.Run(new CrawlerApp()); 
      } 
      catch (Exception e) 
      { 
       LogError.WriteError("Napaka: " + e.Message); 
       LogError.WriteError("StackTrace: " + e.StackTrace); 
      } 

代码2:

#region 

using System; 
using System.Collections.Generic; 
using System.ComponentModel; 
using System.Configuration; 
using System.Diagnostics; 
using System.Linq; 
using System.Net; 
using System.Runtime.InteropServices; 
using System.Windows.Forms; 
using WebCrawler.Core.DataInterfaces; 
using WebCrawler.Core.Entities; 
using WebCrawler.Data; 
using WebCrawler.Lib; 
using WebCrawler.Logic; 

#endregion 

namespace ViaMura.CrawlerApp 
{ 
    public delegate void WebSiteVisitedCallback(WebSiteVisitedEventArgs args); 

    public partial class CrawlerApp : Form 
    { 
     #region Properties 

     private IDaoFactory _daoFactory; 
     private IList<Agencies> agencies; 
     private Agencies agency; 
     private CrawlerManager manager; 

     private IDaoFactory DaoFactory 
     { 
      get 
      { 
       if (_daoFactory == null) 
       { 
        _daoFactory = new NHibernateDaoFactory(ConfigurationManager.AppSettings["NHibernateConfigPath"]); 
        return _daoFactory; 
       } 
       else 
        return _daoFactory; 
      } 
     } 

     private string ConnectionString 
     { 
      get { return ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString; } 
     } 

     #endregion 

     #region Methods 

     //static uint LOAD_LIBRARY_AS_DATAFILE = 0x00000002; 
     //static uint LOAD_LIBRARY_AS_DATAFILE_EXCLUSIVE = 0x00000040; 
     //static uint LOAD_WITH_ALTERED_SEARCH_PATH = 0x00000008; 

     public CrawlerApp() 
     {   
      InitializeComponent(); 
      //LoadDLL();   
      Init();    
      LoadAgenciesData();    
     } 

     /*[DllImport("kernel32.dll")] 
     private static extern IntPtr LoadLibraryEx(string dllFilePath, IntPtr hFile, uint dwFlags); 

     [DllImport("kernel32.dll")] 
     public static extern bool FreeLibrary(IntPtr dllPointer); 

     private IntPtr LoadWin32Library(string dllFilePath) 
     { 
      try 
      { 
       IntPtr moduleHandle = LoadLibraryEx(dllFilePath, IntPtr.Zero, LOAD_WITH_ALTERED_SEARCH_PATH); 
       if (moduleHandle == IntPtr.Zero) 
       { 
        // I'm gettin last dll error 
        int errorCode = Marshal.GetLastWin32Error(); 
        throw new ApplicationException(
         string.Format("There was an error during dll loading : {0}, error - {1}", dllFilePath, errorCode) 
         ); 
       } 

       return moduleHandle; 
      } 
      catch (Exception exc) 
      { 
       throw new Exception(String.Format("Couldn't load library {0}{1}{2}", dllFilePath, Environment.NewLine, exc.Message), exc); 
      } 
     }*/ 

     private void Init() 
     { 
      manager = new CrawlerManager(DaoFactory, ConnectionString); 
      manager.OnWebSiteVisited += manager_OnWebSiteVisited; 

      timerSetTime.Start(); 
     } 

     /*private void LoadDLL() 
     { 
      string XulRunnerPath = @"D:\PROJEKTI\crawler\WebCrawlerSuite\NCrawler\GeckoEngine\xulRunner"; 
      //string XulRunnerPath = @"D:\Development\Own\ViaMura\WebCrawlerSuite\NCrawler\GeckoEngine\xulRunner"; 

      string[] files = Directory.GetFiles(XulRunnerPath, "*.dll"); 
      foreach (var file in files) 
      { 
       LoadWin32Library(file); 
      } 
     }*/ 

     private void LoadAgenciesData() 
     { 
      agencies = DaoFactory.GetAgenciesDao().GetAll(); 
      agencies = agencies.OrderBy(a => a.LoadCrawlerDate).ToList(); //TODO performance OrderBy 
     } 

     private void timerSetTime_Tick(object sender, EventArgs e) 
     { 
      lblCurrentTime.Text = DateTime.Now.ToString(); 

      foreach (var tmpAgency in agencies) 
      { 
       if (!tmpAgency.Active || bwCrawler.IsBusy) continue; 

       DateTime? crawlerTime; 
       if (tmpAgency.LoadCrawlerDate != null) 
       { 
        crawlerTime = ((DateTime) tmpAgency.LoadCrawlerDate).AddMinutes(tmpAgency.CrawlerDelayInMinutes); 
       } 
       else 
        crawlerTime = null; 

       if (crawlerTime == null || DateTime.Now > crawlerTime) 
       { 
        try 
        { 
         txtStatus.Text = "Start crawler: " + tmpAgency.Name + " " + DateTime.Now + " " + txtStatus.Text + Environment.NewLine + txtStatus.Text; 
        } 
        catch (Exception ex) 
        { 
         txtStatus.Text = "Error: " + ex.Message; 
        } 

        if (tmpAgency.LoadCrawlerDate != null) 
        { 
         tmpAgency.LoadCrawlerDate = ((DateTime) tmpAgency.LoadCrawlerDate).AddDays(1); 
        } 
        else 
         tmpAgency.LoadCrawlerDate = null; 

        agency = tmpAgency; 
        bwCrawler.RunWorkerAsync(); 
       } 
      } 
     } 

     private void manager_OnWebSiteVisited(object source, WebSiteVisitedEventArgs args) 
     { 
      try 
      { 
       txtStatus.Invoke(new WebSiteVisitedCallback(WebSiteVisited), new object[] { args }); 
      } 
      catch (Exception ex) 
      { 
       throw new Exception(ex.Message); 
      } 
     } 

     private void WebSiteVisited(WebSiteVisitedEventArgs args) 
     { 
      txtStatus.Text = args.Status + " " + args.VisitedUrl + Environment.NewLine + txtStatus.Text; 

      if (args.Status) 
      { 
       lblNumberOfMatches.Text = (Convert.ToInt32(lblNumberOfMatches.Text) + 1).ToString(); 
      } 
      else 
      { 
       lblNumberOfFailures.Text = (Convert.ToInt32(lblNumberOfFailures.Text) + 1).ToString(); 
      } 

      if (txtStatus.Text.Split(new[] { Environment.NewLine }, StringSplitOptions.None).Length > 200) 
      { 
       txtStatus.Text = string.Empty; 
      } 
     } 

     private void bwCrawler_DoWork(object sender, DoWorkEventArgs e) 
     { 
      manager.ExtractDataFromAgency(agency); 
     } 

     private void bwCrawler_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) 
     { 
      txtStatus.Text = Environment.NewLine + "End and Saved last CrawledDate: " + DateTime.Now + 
          Environment.NewLine + txtStatus.Text; 

      try 
      { 
       IAgenciesDao aDao = DaoFactory.GetAgenciesDao(); 

       agency = aDao.GetById(agency.idAgencies, false); 
       agency.LoadCrawlerDate = DateTime.Now; 

       aDao.SaveOrUpdate(agency); 
       aDao.CommitChanges(); 
      } 
      catch (Exception ex) 
      { 
       txtStatus.Text = ex.Message; 
      } 

      LoadAgenciesData(); 
     } 

     #endregion 
    } 
} 
+3

我们需要更多的信息 - 什么是它崩溃时它在做什么?你已经尝试了什么?如果使用调试器并逐步完成,会发生什么?请阅读http://tinyurl.com/so-hints – 2011-04-07 16:19:30

+0

你的主要方法 – 2011-04-07 16:22:00

+0

应用程序刚刚关闭,没有错误什么都没有。尝试赶上excpetion如果是一个......它不会马上工作一小时后停止... – senzacionale 2011-04-07 16:25:33

回答

1
+0

是的,我正在运行nod32。我会看看它。谢谢 – senzacionale 2011-04-07 19:54:50

0

您可以尝试添加额外的参数的陷阱:

catch (Exception e)    
{ 
    LogError.WriteError("Napaka: " + e.Message); 
    LogError.WriteError("StackTrace: " + e.StackTrace); 
} 
catch 
{ 
    LogError.WriteError("Untyped Exception"); 
} 

在某些情况下的例外是.NET异常类型的不是。 虽然这个问题是特定于CLR 1.1:Throwing Exceptions That Are Not Exceptions

还讨论见Catch Exception treatment

附加link:“如果程序使用其他语言编写的库,那么有可能是不是从派生的异常class Exception。这种异常可以通过无参数的catch语句来处理。“

+0

这里没有错误...此代码从不执行错误。 – senzacionale 2011-04-07 16:48:00