Added ApplicationBase.InitializeOutOfBrowserUpdate to Silverlight library.

Fixed race condition in DirectSound wrapper; between SetVolume and Uninitialize.

--HG--
extra : convert_revision : svn%3Affd33b8c-2492-42e0-bdc5-587b920b7d6d/trunk%4050691
This commit is contained in:
Sean Fausett 2010-08-22 11:04:52 +00:00
parent bf2c8e9b43
commit 5485e01e02
3 changed files with 48 additions and 7 deletions

View File

@ -29,9 +29,12 @@ public void Dispose()
public void SetVolume(double volume) public void SetVolume(double volume)
{ {
int attenuation = (volume < 0.01) ? (int)BufferVolume.Min : (int)Math.Floor(100 * 20 * Math.Log10(volume)); // 100 db int attenuation = (volume < 0.01) ? (int)BufferVolume.Min : (int)Math.Floor(100 * 20 * Math.Log10(volume)); // 100 db
if (_buffer != null) lock (_bufferLock)
{ {
_buffer.SetVolume(attenuation); if (_buffer != null)
{
_buffer.SetVolume(attenuation);
}
} }
} }
@ -116,11 +119,14 @@ private void UpdateBuffer(int offset, int count, BufferLock flags, Action<IntPtr
private void Uninitialize() private void Uninitialize()
{ {
if (_buffer != null) lock (_bufferLock)
{ {
_buffer.Stop(); if (_buffer != null)
Marshal.ReleaseComObject(_buffer); {
_buffer = null; _buffer.Stop();
Marshal.ReleaseComObject(_buffer);
_buffer = null;
}
} }
if (_device != null) if (_device != null)
{ {
@ -157,6 +163,7 @@ private void Run() // com mta thread
private IntPtr _window; private IntPtr _window;
private IDirectSound _device; private IDirectSound _device;
private IDirectSoundBuffer _buffer; private IDirectSoundBuffer _buffer;
private object _bufferLock = new object();
private Action<IntPtr, int> _updater; private Action<IntPtr, int> _updater;
private AutoResetEvent _position1Event = new AutoResetEvent(false); private AutoResetEvent _position1Event = new AutoResetEvent(false);

View File

@ -1,4 +1,5 @@
using System.Diagnostics; using System;
using System.Diagnostics;
using System.Text; using System.Text;
using System.Windows; using System.Windows;
#if WINDOWS_PHONE #if WINDOWS_PHONE
@ -24,6 +25,17 @@ public ApplicationBase(string name)
//AppDomain.CurrentDomain.UnhandledException += OnAppDomainUnhandledException; //AppDomain.CurrentDomain.UnhandledException += OnAppDomainUnhandledException;
} }
#if !WINDOWS_PHONE
protected void InitializeOutOfBrowserUpdate()
{
if (IsRunningOutOfBrowser)
{
CheckAndDownloadUpdateCompleted += OnApplicationCheckAndDownloadUpdateCompleted;
CheckAndDownloadUpdateAsync();
}
}
#endif
#if WINDOWS_PHONE #if WINDOWS_PHONE
protected void InitializePhoneApplication() protected void InitializePhoneApplication()
{ {
@ -53,6 +65,27 @@ private string GetExceptionCaption(string title, bool isTerminating = false)
return caption.ToString(); return caption.ToString();
} }
#if !WINDOWS_PHONE
private void OnApplicationCheckAndDownloadUpdateCompleted(object sender, CheckAndDownloadUpdateCompletedEventArgs e)
{
if (e.Error != null)
{
if (e.Error is PlatformNotSupportedException)
{
MessageBox.Show("An application update is available, but it requires the latest version of Silverlight.");
}
else if (Debugger.IsAttached)
{
Debugger.Break();
}
}
else if (e.UpdateAvailable)
{
MessageBox.Show("An application update was downloaded. Restart the application to run the latest version.");
}
}
#endif
private void OnApplicationUnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e) private void OnApplicationUnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
{ {
MessageBox.Show(e.ExceptionObject.ToString(), GetExceptionCaption("Application Exception"), MessageBoxButton.OK); MessageBox.Show(e.ExceptionObject.ToString(), GetExceptionCaption("Application Exception"), MessageBoxButton.OK);

View File

@ -8,6 +8,7 @@ public MainApp() :
base("Virtu") base("Virtu")
{ {
InitializeComponent(); InitializeComponent();
InitializeOutOfBrowserUpdate();
} }
} }
} }