gush3l
gush3l
CC#
Created by gush3l on 3/25/2023 in #help
❔ Why is the order of execution wrong?
I have this code inside an async clipboard changes listener
public static Dictionary<string, object> ClipboardData = new();

private async void TrackClipboardChanges_EventHandler(object sender, object e)
{
var dataPackageView = Clipboard.GetContent();
if (dataPackageView.Contains(StandardDataFormats.Text))
{
string text;
try
{
text = await dataPackageView.GetTextAsync();
if (text.Length > 67108864)
{
GC.Collect();
GC.WaitForPendingFinalizers();
return;
}

Debug.WriteLine("----------------------------- (1)");
foreach (var dictionaryValue in ClipboardData.Values)
{
Debug.WriteLine(dictionaryValue + " " + text);
if (dictionaryValue.ToString() == text) return;
}
Debug.WriteLine("----------------------------- (2)");

AddEntryToClipboardData(ClipboardItemType.Text, text);
return;
}
catch (Exception ex)
{
Debug.WriteLine(ex);
return;
}
}

[More code but it doesn't matter in this case]
public static Dictionary<string, object> ClipboardData = new();

private async void TrackClipboardChanges_EventHandler(object sender, object e)
{
var dataPackageView = Clipboard.GetContent();
if (dataPackageView.Contains(StandardDataFormats.Text))
{
string text;
try
{
text = await dataPackageView.GetTextAsync();
if (text.Length > 67108864)
{
GC.Collect();
GC.WaitForPendingFinalizers();
return;
}

Debug.WriteLine("----------------------------- (1)");
foreach (var dictionaryValue in ClipboardData.Values)
{
Debug.WriteLine(dictionaryValue + " " + text);
if (dictionaryValue.ToString() == text) return;
}
Debug.WriteLine("----------------------------- (2)");

AddEntryToClipboardData(ClipboardItemType.Text, text);
return;
}
catch (Exception ex)
{
Debug.WriteLine(ex);
return;
}
}

[More code but it doesn't matter in this case]
But the output in the debug console is the following
----------------------------- (1)
----------------------------- (2)
c8c876ee-5961-4822-a9a5-ee086633c724_Text
----------------------------- (1)
salut salut
----------------------------- (1)
----------------------------- (2)
c8c876ee-5961-4822-a9a5-ee086633c724_Text
----------------------------- (1)
salut salut
Note that
----------------------------- (2)
----------------------------- (2)
doesn't come out at the end if there's something in ClipboardData for some reason What am I doing wrong?
26 replies
CC#
Created by gush3l on 3/20/2023 in #help
❔ Need help with giant amount of data stored in clipboard
I am trying to keep a history of the user's clipboard locally, but if I load into memory a giant clipboard text (like 40MB+) some exceptions come up and stuff. How should I manage such big amounts of data and also keep ram usage as low as possible?
18 replies