Click here to Skip to main content
15,895,606 members
Articles / Programming Languages / C#

Fun with C# and the Flash Player 8 External API

Rate me:
Please Sign up or sign in to vote.
4.72/5 (31 votes)
19 Oct 20054 min read 543.4K   13.8K   172  
Demonstrates how to communicate between Flash Player 8 and C# using the new External API
using System;
using System.Diagnostics;
using System.Windows.Forms;

namespace Vml.FLVPlayer
{
	/// <summary>
	/// Summary description for ExceptionUtilities.
	/// </summary>
	public sealed class ExceptionUtilities
	{
        private const string EventLogSource = "FLVPlayer";

        private static bool _eventLogInitialized;
        private static EventLog _eventLog;

        static ExceptionUtilities()
        {
            InitializeEventLog();
            _eventLog = new EventLog("Application");
            _eventLog.Source = ExceptionUtilities.EventLogSource;
        }

		private ExceptionUtilities(){}

        public static void DisplayException(Exception ex)
        {
            ExceptionUtilities.DisplayException("An unknown error occurred.", ex);
        }

        public static void DisplayException(string message)
        {
            MessageBox.Show(message, "Exception Encountered", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        public static void DisplayException(string message, Exception ex)
        {
            LogException(message, ex);
            MessageBox.Show(message + "\n\nBelow are the details of the exception:\n\n" + ex.ToString(), "Exception Encountered", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }

        public static void InitializeEventLog()
        {
            if(!ExceptionUtilities._eventLogInitialized)
            {
                if(!EventLog.SourceExists(ExceptionUtilities.EventLogSource))
                {
                    EventLog.CreateEventSource(ExceptionUtilities.EventLogSource, "Application");
                }

                ExceptionUtilities._eventLogInitialized = true;
            }
        }

        public static void LogException(Exception ex)
        {
            LogException(null, ex);
        }

        public static void LogException(string message, Exception ex)
        {
            try
            {
                string entryMessage;

                if(message != null && message.Length > 0)
                {
                    entryMessage = string.Format("{0}\n\n{1}\n{2}", message, ex.Message, ex.StackTrace);
                }
                else
                {
                    entryMessage = string.Format("{0}\n{2}", ex.Message, ex.StackTrace);
                }

                ExceptionUtilities._eventLog.WriteEntry(entryMessage);
            }
            // Just to be safe since we are logging
            catch(Exception exception){}
        }
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
.NET Software Developer

Education
- Working towards M.S. Computer Science
- B.S. Computer Science
- B.S. Computer Information Systems
- Minor Mathematics

Professional
- Microsoft Certified Application Developer
- Microsoft Certified Professional
- C# ASP.NET Developer (4 years)

Other Interests
- Flash Remoting
- Video Encoding (Windows Media and Flash Video)
- Microsoft Content Management Server

More Programming Thoughts and Tips
- http://gabewishnie.blogspot.com

Comments and Discussions