开发者

application stop unexpectedly

Why did my application stop unexpectedly? I tried everything to solve the error but I can not find the solution. This is a Windows application.

UPDATE:

event viewer:

1

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.

2

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 

3

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.

code 1:

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

code 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)
                {
               开发者_如何学Go     _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
    }
}


Are you running NOD32 anti-virus? If so, Google suggests that could be the problem:

http://connect.microsoft.com/VisualStudio/feedback/details/93618/net-remoting-throws-system-accessviolationexception-when-closing-client

http://social.msdn.microsoft.com/Forums/en-US/netfxremoting/thread/bc72660e-d60d-4b05-b217-d563a12cb8c1/

http://www.eggheadcafe.com/software/aspnet/30803254/accessviolationexception-from-ossockrecv-when-using-webrequest.aspx

http://www.ureader.com/msg/1434893.aspx


You may try to add additional parameterless catch:

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

In some cases exceptions are not of .net Exception type. Though this issue is specific to CLR 1.1: Throwing Exceptions That Are Not Exceptions

See also discussion at Catch Exception treatment

Additional link: "If the program uses libraries written in other languages, then there may be an exception that is not derived from the class Exception. Such exceptions can be handled by the parameter-less catch statement."

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜