Hi I am trying to set achieve skype like notification for my wpf application tired solutions to achieve this from code behind but either getting stuck at an error "The calling thread cannot access the object because different thread owns it" or when i create a fresh thread and add overlay to TaskbarItemInfo nothing happens
What I have tried:
public void createIcon(string countNot)
{
try
{
RectangleF rectF = new RectangleF(0, 0, 40, 40);
Bitmap bitmap = new Bitmap(40, 40, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
Graphics g = Graphics.FromImage(bitmap);
g.FillRectangle(System.Drawing.Brushes.White, 0, 0, 40, 40);
g.DrawString(countNot, new Font("Arial", 25), System.Drawing.Brushes.Black, new PointF(0, 0));
IntPtr hBitmap = bitmap.GetHbitmap();
ImageSource wpfBitmap =
Imaging.CreateBitmapSourceFromHBitmap(
hBitmap, IntPtr.Zero, Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
new Thread(() =>
{
Thread.CurrentThread.IsBackground = false;
Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Background, (SendOrPostCallback)delegate {
TaskbarItemInfo ittem = new TaskbarItemInfo();
ittem.Overlay = wpfBitmap;
}, null);
}).Start();
}
catch (Exception ex)
{
string path = @"C:\Logs\logs.txt";
File.AppendAllLines(path, new[] { "---------------------" + "\rn" + ex.Message + "\n" + " stack trace: " + ex.StackTrace });
}
}