Here are the examples of the csharp api System.GC.KeepAlive(object) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
2249 Examples
19
Source : BufferedChannelTests.cs
with Apache License 2.0
from busterwood
with Apache License 2.0
from busterwood
public static void memory(Test t)
{
if (Tests.Short)
t.Skip();
var before = GC.GetTotalMemory(true);
var chans = new BufferedChannel<int>[10000];
for (int i = 0; i < chans.Length; i++)
{
chans[i] = new BufferedChannel<int>(3);
}
var after = GC.GetTotalMemory(true);
GC.KeepAlive(chans);
var diff = after - before - (chans.Length * 4);
var kb = diff / 1024;
t.Log("10,000 buffered channels of size 3 takes " + kb + "KB");
}
19
Source : ChannelTests.cs
with Apache License 2.0
from busterwood
with Apache License 2.0
from busterwood
public static void memory(Test t)
{
if (Tests.Short)
t.Skip();
var before = GC.GetTotalMemory(true);
var chans = new Channel<int>[10000];
for (int i = 0; i < chans.Length; i++)
{
chans[i] = new Channel<int>();
}
var after = GC.GetTotalMemory(true);
GC.KeepAlive(chans);
var diff = after - before - (chans.Length * 4);
var kb = diff / 1024;
t.Log("10,000 changes takes " + kb + "KB");
}
19
Source : MixedReadWriteOverheadTests.cs
with Apache License 2.0
from busterwood
with Apache License 2.0
from busterwood
public void BitPseudoLru_cache_half(Test t)
{
foreach (var items in testSizes)
{
string[] keys = CreateKeyStrings(items);
var pm = new PerformaceMonitor(start: true);
var cache = new BitPseudoLruMap<string, string>(valueIsKey, items / 2);
ReadMixKeys(keys, cache, t);
pm.Stop();
t.Log($"BitPseudoLru_cache_half of {items} items {pm.Stop()}");
GC.KeepAlive(cache);
GC.KeepAlive(keys);
}
}
19
Source : MixedReadWriteOverheadTests.cs
with Apache License 2.0
from busterwood
with Apache License 2.0
from busterwood
public void generational_cache_half(Test t)
{
foreach (var items in testSizes)
{
string[] keys = CreateKeyStrings(items);
var pm = new PerformaceMonitor(start: true);
var cache = valueIsKey.WithGenerationalCache(items / 4, null);
ReadMixKeys(keys, cache, t);
cache.Dispose();
pm.Stop();
t.Log($"generational_cache_half of {items} items {pm.Stop()}");
GC.KeepAlive(cache);
GC.KeepAlive(keys);
}
}
19
Source : MixedReadWriteOverheadTests.cs
with Apache License 2.0
from busterwood
with Apache License 2.0
from busterwood
public void generational_timed(Test t)
{
foreach (var items in testSizes)
{
string[] keys = CreateKeyStrings(items);
var pm = new PerformaceMonitor(start: true);
var cache = valueIsKey.WithGenerationalCache(null, TimeSpan.FromMilliseconds(100));
ReadMixKeys(keys, cache, t);
cache.Dispose();
pm.Stop();
t.Log($"generational_timed of {items} items {pm.Stop()}");
GC.KeepAlive(cache);
GC.KeepAlive(keys);
}
}
19
Source : ThunderingHerdOverheadTests.cs
with Apache License 2.0
from busterwood
with Apache License 2.0
from busterwood
public void generational_cache_half(Test t)
{
var cache = valueIsKey.WithThunderingHerdProtection().WithGenerationalCache(keys.Length / 4, null);
ReadMixKeys(keys, cache, t);
cache.Dispose();
Console.WriteLine($"Generational half {valueIsKey.HitCount} hits to underlying data source, {pm.Stop()}");
GC.KeepAlive(cache);
GC.KeepAlive(keys);
}
19
Source : ThunderingHerdOverheadTests.cs
with Apache License 2.0
from busterwood
with Apache License 2.0
from busterwood
public void generational_timed(Test t)
{
var cache = valueIsKey.WithThunderingHerdProtection().WithGenerationalCache(null, TimeSpan.FromSeconds(5));
ReadMixKeys(keys, cache, t);
cache.Dispose();
Console.WriteLine($"Generational timed {valueIsKey.HitCount} hits to underlying data source, {pm.Stop()}");
GC.KeepAlive(cache);
GC.KeepAlive(keys);
}
19
Source : MixedReadWriteOverheadTests.cs
with Apache License 2.0
from busterwood
with Apache License 2.0
from busterwood
public void generational_timed(Test t)
{
foreach (var items in testSizes)
{
string[] keys = CreateKeyStrings(items);
var pm = new PerformaceMonitor(start: true);
var cache = valueIsKey.WithGenerationalCache(null, TimeSpan.FromMilliseconds(100));
ReadMixKeys(keys, cache, t);
cache.Dispose();
pm.Stop();
t.Log($"generational_timed of {items} items {pm.Stop()}");
GC.KeepAlive(cache);
GC.KeepAlive(keys);
}
}
19
Source : ThunderingHerdOverheadTests.cs
with Apache License 2.0
from busterwood
with Apache License 2.0
from busterwood
public void BitPseudoLru_cache_half(Test t)
{
var cache = new BitPseudoLruMap<string, string>(valueIsKey.WithThunderingHerdProtection(), keys.Length / 2);
ReadMixKeys(keys, cache, t);
Console.WriteLine($"BitPseudoLru half {valueIsKey.HitCount} hits to underlying data source, {pm.Stop()}");
GC.KeepAlive(cache);
GC.KeepAlive(keys);
}
19
Source : ThunderingHerdOverheadTests.cs
with Apache License 2.0
from busterwood
with Apache License 2.0
from busterwood
public void BitPseudoLru_cache_half(Test t)
{
var cache = new BitPseudoLruMap<string, string>(valueIsKey.WithThunderingHerdProtection(), keys.Length / 2);
ReadMixKeys(keys, cache, t);
Console.WriteLine($"BitPseudoLru half {valueIsKey.HitCount} hits to underlying data source, {pm.Stop()}");
GC.KeepAlive(cache);
GC.KeepAlive(keys);
}
19
Source : ThunderingHerdOverheadTests.cs
with Apache License 2.0
from busterwood
with Apache License 2.0
from busterwood
public void generational_cache_half(Test t)
{
var cache = valueIsKey.WithThunderingHerdProtection().WithGenerationalCache(keys.Length / 4, null);
ReadMixKeys(keys, cache, t);
cache.Dispose();
Console.WriteLine($"Generational half {valueIsKey.HitCount} hits to underlying data source, {pm.Stop()}");
GC.KeepAlive(cache);
GC.KeepAlive(keys);
}
19
Source : ThunderingHerdOverheadTests.cs
with Apache License 2.0
from busterwood
with Apache License 2.0
from busterwood
public void generational_timed(Test t)
{
var cache = valueIsKey.WithThunderingHerdProtection().WithGenerationalCache(null, TimeSpan.FromSeconds(5));
ReadMixKeys(keys, cache, t);
cache.Dispose();
Console.WriteLine($"Generational timed {valueIsKey.HitCount} hits to underlying data source, {pm.Stop()}");
GC.KeepAlive(cache);
GC.KeepAlive(keys);
}
19
Source : CefBaseRefCounted.cs
with MIT License
from CefNet
with MIT License
from CefNet
public unsafe cef_base_ref_counted_t* GetNativeInstance()
{
cef_base_ref_counted_t* instance = (cef_base_ref_counted_t*)Volatile.Read(ref _instance);
if (instance == null)
throw new ObjectDisposedException(this.GetType().Name);
instance->AddRef();
GC.KeepAlive(this);
return instance;
}
19
Source : CefBaseRefCounted.cs
with MIT License
from CefNet
with MIT License
from CefNet
[EditorBrowsable(EditorBrowsableState.Never)]
public void AddRef()
{
NativeInstance->AddRef();
GC.KeepAlive(this);
}
19
Source : CefFrame.cs
with MIT License
from CefNet
with MIT License
from CefNet
public unsafe CefFrame[] GetFrames()
{
long frameid = this.Identifier;
CefBrowser browser = this.Browser;
if (browser is null)
{
#if NET45
return new CefFrame[0];
#else
return Array.Empty<CefFrame>();
#endif
}
long[] ids = browser.GetFrameIdentifiers();
var frames = new List<CefFrame>(ids.Length);
foreach (long fid in ids)
{
cef_frame_t* frame = browser.NativeInstance->GetFrameByIdent(fid);
if (frame == null)
continue;
cef_frame_t* parent = frame->GetParent();
if (parent != null)
{
long parentid = parent->GetIdentifier();
((cef_base_ref_counted_t*)parent)->Release();
if (parentid == frameid)
{
frames.Add(CefFrame.Wrap<CefFrame>(f => new CefFrame((cef_frame_t*)f), frame));
continue;
}
}
((cef_base_ref_counted_t*)frame)->Release();
}
GC.KeepAlive(browser);
return frames.ToArray();
}
19
Source : CefRequestContext.cs
with MIT License
from CefNet
with MIT License
from CefNet
private unsafe void SetPreferenceInternal(string name, CefValue value, TaskCompletionSource<bool> taskCompletion)
{
int retval;
string errorMsg;
fixed (char* s0 = name)
{
cef_string_t error;
cef_string_t cstr0 = new cef_string_t { Str = s0, Length = name.Length };
retval = NativeInstance->SetPreference(&cstr0, value is null ? null : value.GetNativeInstance(), &error);
GC.KeepAlive(this);
errorMsg = CefString.ReadAndFree(&error);
}
if (retval != 0)
{
taskCompletion?.TrySetResult(true);
return;
}
Exception exception = errorMsg is null ? new InvalidOperationException() : new InvalidOperationException(errorMsg);
if (taskCompletion is null)
throw exception;
taskCompletion.TrySetException(exception);
}
19
Source : CefV8Context.cs
with MIT License
from CefNet
with MIT License
from CefNet
public CefV8Value Eval(string code, string scriptUrl, int line = 1)
{
if (line <= 0)
throw new ArgumentOutOfRangeException(nameof(line));
if (code is null)
throw new ArgumentNullException(nameof(code));
fixed (char* s0 = code)
fixed (char* s1 = scriptUrl)
{
var cstr0 = new cef_string_t { Str = s0, Length = code.Length };
var cstr1 = new cef_string_t { Str = s1, Length = scriptUrl != null ? scriptUrl.Length : 0 };
cef_v8value_t* rv = null;
cef_v8value_t** pRv = &rv;
cef_v8exception_t* jsex = null;
cef_v8exception_t** pJsex = &jsex;
if (NativeInstance->Eval(&cstr0, &cstr1, line, pRv, pJsex) != 0)
{
return CefV8Value.Wrap(CefV8Value.Create, rv);
}
GC.KeepAlive(this);
throw new CefNetJSExcepton(CefV8Exception.Wrap(CefV8Exception.Create, jsex));
}
}
19
Source : CefV8Value.cs
with MIT License
from CefNet
with MIT License
from CefNet
public bool CopyV8StringToCefValue(CefValue value)
{
if (value == null)
throw new ArgumentNullException(nameof(value));
if (!IsString)
throw new InvalidOperationException();
cef_string_userfree_t userfreeStr = NativeInstance->GetStringValue();
try
{
return value.NativeInstance->SetString((cef_string_t*)userfreeStr.Base.Base) != 0;
}
finally
{
CefString.Free(userfreeStr);
GC.KeepAlive(this);
}
}
19
Source : CefV8Value.cs
with MIT License
from CefNet
with MIT License
from CefNet
public CefV8Value GetValue(ArraySegment<string> names)
{
if (names.Count <= 0)
throw new ArgumentOutOfRangeException(nameof(names));
cef_v8value_t* value = null;
cef_v8value_t* self = GetNativeInstance();
foreach (string name in names)
{
try
{
if (self->IsNull() != 0)
throw new InvalidOperationException($"Cannot read property '{name}' of null.");
if (self->IsUndefined() != 0)
throw new InvalidOperationException($"Cannot read property '{name}' of undefined.");
if (string.IsNullOrEmpty(name))
throw new ArgumentOutOfRangeException(nameof(names));
fixed (char* s = name)
{
var aName = new cef_string_t { Str = s, Length = name.Length };
value = self->GetValueByKey(&aName);
}
}
finally
{
self->@base.Release();
}
if (value == null)
throw new InvalidOperationException();
self = value;
}
GC.KeepAlive(this);
return CefV8Value.Wrap(CefV8Value.Create, value);
}
19
Source : CefFileDialogCallback.cs
with MIT License
from CefNet
with MIT License
from CefNet
public unsafe virtual void Cancel()
{
NativeInstance->Cancel();
GC.KeepAlive(this);
}
19
Source : CefFrame.cs
with MIT License
from CefNet
with MIT License
from CefNet
public unsafe virtual void Redo()
{
NativeInstance->Redo();
GC.KeepAlive(this);
}
19
Source : CefFrame.cs
with MIT License
from CefNet
with MIT License
from CefNet
public unsafe virtual void Paste()
{
NativeInstance->Paste();
GC.KeepAlive(this);
}
19
Source : CefFrame.cs
with MIT License
from CefNet
with MIT License
from CefNet
public unsafe virtual void ViewSource()
{
NativeInstance->ViewSource();
GC.KeepAlive(this);
}
19
Source : CefFrame.cs
with MIT License
from CefNet
with MIT License
from CefNet
public unsafe virtual void GetSource(CefStringVisitor visitor)
{
NativeInstance->GetSource((visitor != null) ? visitor.GetNativeInstance() : null);
GC.KeepAlive(this);
}
19
Source : CefFrame.cs
with MIT License
from CefNet
with MIT License
from CefNet
public unsafe virtual void GetText(CefStringVisitor visitor)
{
NativeInstance->GetText((visitor != null) ? visitor.GetNativeInstance() : null);
GC.KeepAlive(this);
}
19
Source : CefFrame.cs
with MIT License
from CefNet
with MIT License
from CefNet
public unsafe virtual void LoadRequest(CefRequest request)
{
NativeInstance->LoadRequest((request != null) ? request.GetNativeInstance() : null);
GC.KeepAlive(this);
}
19
Source : CefFrame.cs
with MIT License
from CefNet
with MIT License
from CefNet
public unsafe virtual void LoadUrl(string url)
{
fixed (char* s0 = url)
{
var cstr0 = new cef_string_t { Str = s0, Length = url != null ? url.Length : 0 };
NativeInstance->LoadUrl(&cstr0);
}
GC.KeepAlive(this);
}
19
Source : CefFrame.cs
with MIT License
from CefNet
with MIT License
from CefNet
public unsafe virtual void ExecuteJavaScript(string code, string scriptUrl, int startLine)
{
fixed (char* s0 = code)
fixed (char* s1 = scriptUrl)
{
var cstr0 = new cef_string_t { Str = s0, Length = code != null ? code.Length : 0 };
var cstr1 = new cef_string_t { Str = s1, Length = scriptUrl != null ? scriptUrl.Length : 0 };
NativeInstance->ExecuteJavaScript(&cstr0, &cstr1, startLine);
}
GC.KeepAlive(this);
}
19
Source : CefFrame.cs
with MIT License
from CefNet
with MIT License
from CefNet
public unsafe virtual void VisitDOM(CefDOMVisitor visitor)
{
NativeInstance->VisitDOM((visitor != null) ? visitor.GetNativeInstance() : null);
GC.KeepAlive(this);
}
19
Source : CefFrame.cs
with MIT License
from CefNet
with MIT License
from CefNet
public unsafe virtual void SendProcessMessage(CefProcessId targetProcess, CefProcessMessage message)
{
NativeInstance->SendProcessMessage(targetProcess, (message != null) ? message.GetNativeInstance() : null);
GC.KeepAlive(this);
}
19
Source : CefGetExtensionResourceCallback.cs
with MIT License
from CefNet
with MIT License
from CefNet
public unsafe virtual void Continue(CefStreamReader stream)
{
NativeInstance->Continue((stream != null) ? stream.GetNativeInstance() : null);
GC.KeepAlive(this);
}
19
Source : CefJSDialogCallback.cs
with MIT License
from CefNet
with MIT License
from CefNet
public unsafe virtual void Continue(bool success, string userInput)
{
fixed (char* s1 = userInput)
{
var cstr1 = new cef_string_t { Str = s1, Length = userInput != null ? userInput.Length : 0 };
NativeInstance->Continue(success ? 1 : 0, &cstr1);
}
GC.KeepAlive(this);
}
19
Source : CefPrintSettings.cs
with MIT License
from CefNet
with MIT License
from CefNet
public unsafe virtual void SetOrientation(bool landscape)
{
NativeInstance->SetOrientation(landscape ? 1 : 0);
GC.KeepAlive(this);
}
19
Source : CefRequest.cs
with MIT License
from CefNet
with MIT License
from CefNet
public unsafe virtual void Set(string url, string method, CefPostData postData, CefStringMultimap headerMap)
{
fixed (char* s0 = url)
fixed (char* s1 = method)
{
var cstr0 = new cef_string_t { Str = s0, Length = url != null ? url.Length : 0 };
var cstr1 = new cef_string_t { Str = s1, Length = method != null ? method.Length : 0 };
NativeInstance->Set(&cstr0, &cstr1, (postData != null) ? postData.GetNativeInstance() : null, headerMap);
}
GC.KeepAlive(this);
}
19
Source : CefRunContextMenuCallback.cs
with MIT License
from CefNet
with MIT License
from CefNet
public unsafe virtual void Continue(int commandId, CefEventFlags eventFlags)
{
NativeInstance->Continue(commandId, eventFlags);
GC.KeepAlive(this);
}
19
Source : CefThread.cs
with MIT License
from CefNet
with MIT License
from CefNet
public unsafe virtual void Stop()
{
NativeInstance->Stop();
GC.KeepAlive(this);
}
19
Source : CefWaitableEvent.cs
with MIT License
from CefNet
with MIT License
from CefNet
public unsafe virtual void Signal()
{
NativeInstance->Signal();
GC.KeepAlive(this);
}
19
Source : CefX509Certificate.cs
with MIT License
from CefNet
with MIT License
from CefNet
public unsafe virtual void GetDEREncodedIssuerChain(ref long chainCount, ref CefBinaryValue[] chain)
{
var c1 = new UIntPtr((uint)chain.Length);
cef_binary_value_t** arr1 = (cef_binary_value_t**)Marshal.AllocHGlobal(sizeof(cef_binary_value_t*) * chain.Length);
for (int i = 0; i < chain.Length; i++)
{
var e1 = chain[i];
*(arr1 + i) = e1 != null ? e1.GetNativeInstance() : null;
}
NativeInstance->GetDEREncodedIssuerChain(&c1, arr1);
chainCount = (long)c1;
for (int i = (int)c1; i >= 0; i--)
{
chain[i] = CefBinaryValue.Wrap(CefBinaryValue.Create, *(arr1 + i));
}
Marshal.FreeHGlobal((IntPtr)arr1);
GC.KeepAlive(this);
}
19
Source : ScriptableObjectProvider.cs
with MIT License
from CefNet
with MIT License
from CefNet
internal static CefV8Value CastDotnetTypeToCefV8Value(CefV8Context context, object value, out bool isNew)
{
isNew = true;
if (value is null)
return CefV8Value.CreateNull();
if (value is V8Undefined)
return CefV8Value.CreateUndefined();
switch (value)
{
case string v:
return new CefV8Value(v);
case int v:
return new CefV8Value(v);
case double v:
return new CefV8Value(v);
case bool v:
return new CefV8Value(v);
case DateTime v:
return new CefV8Value(v);
case XrayHandle v:
isNew = (v.dataType != XrayDataType.Object && v.dataType != XrayDataType.Function);
return v.ToCefV8Value(context.Frame);
case ScriptableObject v:
XrayHandle hv = (XrayHandle)v;
isNew = (hv.dataType != XrayDataType.Object && hv.dataType != XrayDataType.Function);
CefV8Value cv8 = hv.ToCefV8Value(context.Frame);
GC.KeepAlive(v);
return cv8;
}
throw new NotImplementedException("Type: " + value.GetType().Name);
}
19
Source : CefAuthCallback.cs
with MIT License
from CefNet
with MIT License
from CefNet
public unsafe virtual void Continue(string username, string preplacedword)
{
fixed (char* s0 = username)
fixed (char* s1 = preplacedword)
{
var cstr0 = new cef_string_t { Str = s0, Length = username != null ? username.Length : 0 };
var cstr1 = new cef_string_t { Str = s1, Length = preplacedword != null ? preplacedword.Length : 0 };
NativeInstance->Continue(&cstr0, &cstr1);
}
GC.KeepAlive(this);
}
19
Source : CefBeforeDownloadCallback.cs
with MIT License
from CefNet
with MIT License
from CefNet
public unsafe virtual void Continue(string downloadPath, bool showDialog)
{
fixed (char* s0 = downloadPath)
{
var cstr0 = new cef_string_t { Str = s0, Length = downloadPath != null ? downloadPath.Length : 0 };
NativeInstance->Continue(&cstr0, showDialog ? 1 : 0);
}
GC.KeepAlive(this);
}
19
Source : CefBrowser.cs
with MIT License
from CefNet
with MIT License
from CefNet
public unsafe virtual void GoBack()
{
NativeInstance->GoBack();
GC.KeepAlive(this);
}
19
Source : CefBrowser.cs
with MIT License
from CefNet
with MIT License
from CefNet
public unsafe virtual void GoForward()
{
NativeInstance->GoForward();
GC.KeepAlive(this);
}
19
Source : CefBrowser.cs
with MIT License
from CefNet
with MIT License
from CefNet
public unsafe virtual void Reload()
{
NativeInstance->Reload();
GC.KeepAlive(this);
}
19
Source : CefBrowser.cs
with MIT License
from CefNet
with MIT License
from CefNet
public unsafe virtual void ReloadIgnoreCache()
{
NativeInstance->ReloadIgnoreCache();
GC.KeepAlive(this);
}
19
Source : CefBrowser.cs
with MIT License
from CefNet
with MIT License
from CefNet
public unsafe virtual void StopLoad()
{
NativeInstance->StopLoad();
GC.KeepAlive(this);
}
19
Source : CefBrowser.cs
with MIT License
from CefNet
with MIT License
from CefNet
public unsafe virtual void GetFrameIdentifiers(ref long identifiersCount, ref long[] identifiers)
{
fixed (long* p1 = identifiers)
{
UIntPtr c1 = new UIntPtr((uint)identifiers.Length);
NativeInstance->GetFrameIdentifiers(&c1, p1);
identifiersCount = (long)c1;
Array.Resize(ref identifiers, (int)c1);
}
GC.KeepAlive(this);
}
19
Source : CefBrowser.cs
with MIT License
from CefNet
with MIT License
from CefNet
public unsafe virtual void GetFrameNames(CefStringList names)
{
NativeInstance->GetFrameNames(names.GetNativeInstance());
GC.KeepAlive(this);
}
19
Source : CefBrowserHost.cs
with MIT License
from CefNet
with MIT License
from CefNet
public unsafe virtual void CloseBrowser(bool forceClose)
{
NativeInstance->CloseBrowser(forceClose ? 1 : 0);
GC.KeepAlive(this);
}
19
Source : CefBrowserHost.cs
with MIT License
from CefNet
with MIT License
from CefNet
public unsafe virtual void RunFileDialog(CefFileDialogMode mode, string replacedle, string defaultFilePath, CefStringList acceptFilters, bool selectedAcceptFilter, CefRunFileDialogCallback callback)
{
fixed (char* s1 = replacedle)
fixed (char* s2 = defaultFilePath)
{
var cstr1 = new cef_string_t { Str = s1, Length = replacedle != null ? replacedle.Length : 0 };
var cstr2 = new cef_string_t { Str = s2, Length = defaultFilePath != null ? defaultFilePath.Length : 0 };
NativeInstance->RunFileDialog(mode, &cstr1, &cstr2, acceptFilters.GetNativeInstance(), selectedAcceptFilter ? 1 : 0, (callback != null) ? callback.GetNativeInstance() : null);
}
GC.KeepAlive(this);
}
See More Examples