我想使用 Windows Azure 虚拟机作为开发机器。我想在该机器上启用声音,以便听到事件声音(错误、警告等)并收听来自 last.fm 的音乐。
Azure 虚拟机上是否可以有声音?
我试过:http : //www.wikihow.com/Hear-Audio-from-the-Remote-PC-when-Using-Remote-Desktop但它没有帮助。
操作系统:Windows Server 2012 R2 / Windows Server 2013
以下代码应该缓存上次读取.这LastValueCache是一个可以被许多线程访问的缓存(这就是我使用共享内存的原因).我可以有竞争条件,但我希望其他线程看到变化LastValueCache.
class Repository
{
public Item LastValueCache
{
get
{
Thread.MemoryBarrier();
SomeType result = field;
Thread.MemoryBarrier();
return result;
}
set
{
Thread.MemoryBarrier();
field = value;
Thread.MemoryBarrier();
}
}
public void Save(Item item)
{
SaveToDatabase(item);
Item cached = LastValueCache;
if (cached == null || item.Stamp > cached.Stamp)
{
LastValueCache = item;
}
}
public void Remove(Timestamp stamp)
{
RemoveFromDatabase(item);
Item cached = LastValueCache;
if (cached != null && cached.Stamp == item.Stamp)
{
LastValueCache = null;
}
} …Run Code Online (Sandbox Code Playgroud) 对于以下场景,使用之间的线程安全性,结果和性能是否有任何区别MemoryBarrier
private SomeType field;
public SomeType Property
{
get
{
Thread.MemoryBarrier();
SomeType result = field;
Thread.MemoryBarrier();
return result;
}
set
{
Thread.MemoryBarrier();
field = value;
Thread.MemoryBarrier();
}
}
Run Code Online (Sandbox Code Playgroud)
和lock声明(Monitor.Enter和Monitor.Exit)
private SomeType field;
private readonly object syncLock = new object();
public SomeType Property
{
get
{
lock (syncLock)
{
return field;
}
}
set
{
lock (syncLock)
{
field = value;
}
}
}
Run Code Online (Sandbox Code Playgroud)
因为引用赋值是原子的所以我认为在这种情况下我们确实需要任何锁定机制.
性能 MemeoryBarrier比Release的锁实现快约2倍.这是我的测试结果:
Lock
Normaly: 5397 ms
Passed as …Run Code Online (Sandbox Code Playgroud) 为什么这两种方法不能同名?是因为 C# 编译器在重载时没有考虑泛型类型约束吗?它可以在 C# 的未来版本中完成吗?
public static TValue GetValueOrNull<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key)
where TValue : class
{
TValue value;
if (dictionary.TryGetValue(key, out value))
return value;
return null;
}
public static TValue? GetValueOrNull<TKey, TValue>(this IDictionary<TKey, TValue> dictionary, TKey key)
where TValue : struct
{
TValue value;
if (dictionary.TryGetValue(key, out value))
return value;
return null;
}
Run Code Online (Sandbox Code Playgroud) 我的项目的LINQ to SQL部分有一个表.

我只是想尝试执行一个简单的查询:
public static string GetMLBID(int fk_players_id)
{
using (MLBDataClassesDataContext context = new MLBDataClassesDataContext())
{
var query = from a in context.players
where a.fk_player_type_id == fk_players_id
select a.mlb_com_id;
foreach (var b in query)
{
Console.WriteLine(b.); //<-- I don't get the properties listed in the "players" table that i linked in the imgur link.
}
}
}
Run Code Online (Sandbox Code Playgroud)
从谷歌的所有例子中我都有"b.",我所拥有的表中的属性应该弹出..但是没有列出.我只获得简单的LINQ运算符和方法.
我觉得我错过了一些非常简单的东西..任何帮助?