private static void EnumerableLazyLoad() { LazyLoading lazy = new LazyLoading(); lazy.GenerateEveryWeekdayTheSameAsTodayToTheNextYear(); return; var map = new Map(); //map.FilterSequence(); map.MapSequence(); }
/// <summary> /// Tests LazyLoading.cs /// </summary> public static void LazyLoading() { Lazy <LazyLoading> lazy = new Lazy <LazyLoading>(); Console.WriteLine("Data Loaded : " + lazy.IsValueCreated); //Whenever following line executes, the value will be populated in the LazyLoading class and //this is how the LazyLoading class will initialize lazily. LazyLoading lazyInstance = lazy.Value; foreach (string tmp in lazyInstance.NamesList) { Console.WriteLine(tmp); } }
private void LoadLazyKeys() { if (LazyLoading == null || !LazyLoading.Values) { return; } if (WeakReference == null || !WeakReference.Values) { foreach (TKey lazyKey in _lazyKeys) { _strongDictionary.Add(lazyKey, LazyLoading.ValueFactory(lazyKey)); } } else { foreach (TKey lazyKey in _lazyKeys) { _weakDictionary.Add(lazyKey, new WeakReference <TValue>(LazyLoading.ValueFactory(lazyKey))); } } _lazyKeys.Clear(); }
private static void _Main(string[] args) { var qts = new QueuedTaskScheduler(TaskScheduler.Default, maxConcurrencyLevel: 4); var options = new ParallelOptions { TaskScheduler = qts }; Task.Factory.StartNew(() => { Parallel.For(0, 100, options, i => { //… }); }, CancellationToken.None, TaskCreationOptions.None, qts); Task.Factory.StartNew(() => { Parallel.For(0, 100, options, i => { //… }); }, CancellationToken.None, TaskCreationOptions.None, qts); using (var e = OsgiEngine.InitWinformEngine("testfolder")) { var host = new Program_(); host.TestItems = LazyLoading.NewAll <ITestMetadata, ITestRunner>(); host.Init(); var records = new List <Record>(); host.Run(records); var data = records.Select( x => new { name = x.Mapper.Name, Iterations = x.Iterations.Select(v => v.Iteration).ToArray(), TimeElapseds = x.Iterations.Select(v => v.TimeElapsed).ToArray(), CPUCycles = x.Iterations.Select(v => v.CPUCycles).ToArray() }).ToArray(); var dir = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var s = JsonConvert.SerializeObject(data, Formatting.None); var file = Path.Combine(dir, "dataJs.js"); using (var writer = new StreamWriter(file)) { writer.Write("dataAll="); writer.Write(s); writer.Write(";"); writer.Flush(); } // var chartfile = Path.Combine(dir, "performance.html"); //Process.Start(new ProcessStartInfo(chartfile)); Process.Start("explorer.exe", "http://localhost:8080/api/v1/users"); Console.ReadLine(); } }
public bool TryGetValue(TKey key, out TValue value) { if (WeakReference == null || !WeakReference.Values) { if (_strongDictionary.ContainsKey(key)) { value = _strongDictionary[key]; return(true); } if (LazyLoading != null && LazyLoading.Values) { if (_lazyKeys.Contains(key)) { _lazyKeys.Remove(key); value = LazyLoading.ValueFactory(key); _strongDictionary.Add(key, value); return(true); } if (LazyLoading.Keys) { value = LazyLoading.ValueFactory(key); _strongDictionary.Add(key, value); return(true); } } } else { if (_weakDictionary.ContainsKey(key)) { if (_weakDictionary[key].TryGetTarget(out value)) { return(true); } if (WeakReference.Values) { _weakDictionary[key] = new WeakReference <TValue>(value); } return(true); } if (LazyLoading != null && LazyLoading.Values) { if (_lazyKeys.Contains(key)) { _lazyKeys.Remove(key); value = LazyLoading.ValueFactory(key); _weakDictionary.Add(key, new WeakReference <TValue>(value)); return(true); } if (LazyLoading.Keys) { value = LazyLoading.ValueFactory(key); _weakDictionary.Add(key, new WeakReference <TValue>(value)); return(true); } } } value = default(TValue); return(false); }
public T Lazy(LazyLoading lazyOption) { _options.Lazy = lazyOption; return(this as T); }
private static IServiceSituation CreateServiceSituation() { return(LazyLoading.New <IServiceSituation>()); }