C# Asynchron Statische Methode [Duplikat]C#

Ein Treffpunkt für C#-Programmierer
Anonymous
 C# Asynchron Statische Methode [Duplikat]

Post by Anonymous »

Ich fühle mich nicht sehr wohl mit dem Begriff asynchroner Aufgaben. Stellen Sie vor der Serialisierung eine legacy serialisierung. Ausgefüllt zu werden, aber das ist nur ein Test.

Code: Select all

public static class SerializationHelper
{
private static readonly LogService _Log = BaseServiceProvider.Current.GetService();
private static StopwatchHelper _Stopwatch = new StopwatchHelper();

public static async Task EyeshotObjectSerialize(object obj)
{
if (obj == null) return null;

_Stopwatch.Restart();

try
{
return await Task.Run(() =>
{
Entity entity = obj is Entity ent ? ent : new Ghost(obj.GetType().Name) { EntityData = obj };

using (MemoryStream ms = new MemoryStream())
{
WriteFileParams wfp = new([entity]);
WriteFile wf = new(wfp, ms);
wf.DoWork();

return ms.ToArray();
}
});
}
catch (Exception ex)
{
_Stopwatch.Stop();

_Log.InfoMainLog(string.Format("{0}\n{1}\n{2}", "Error while EyeshotObjectSerialization", ex.Message, ex.StackTrace));
return null;
}
finally
{
_Log.InfoMainLog(string.Format("== {0}: {1} ==", obj.GetType().Name, _Stopwatch.GetValues("EyeshotObjectSerialized")));
}
}
}
Der Aufruf einer Methode oder ctor

Code: Select all

byte[] _Plane_BA = SerializationHelper.EyeshotObjectSerialize(Plane).Result;

Quick Reply

Change Text Case: 
   
  • Similar Topics
    Replies
    Views
    Last post