在我的 ReceiveCallBack 异步套接字中 Lock() 那里的套接字是个好主意吗?我这么问是因为另一个线程可能同时在套接字上发送数据。
private void ReceiveCallback(IAsyncResult ar)
{
StateObject state = (StateObject)ar.AsyncState;
Socket client = state.workSocket;
lock(client)
{
int bytesRead = client.EndReceive(ar);
// do some work
// Kick off socket to receive async again.
client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
new AsyncCallback(ReceiveCallback), state);
}
}
// This is commonly called by another thread
public void SendMessage(string cmdName, Object data)
{
lock (client)
{
client.Send(arrayofdata, 0, arraylength, 0);
}
}
Run Code Online (Sandbox Code Playgroud) 我正在使用 php 5.2 和 IIS7.5。
我的 NAS 上有一个受用户名和密码保护的网络共享。我无法禁用或更改 NAS 上的身份验证信息。我需要能够通过 php 访问该网络共享。
我做了以下事情:
在 Windows 中创建新用户,其用户名和密码与 NAS 上的用户名和密码一致。创建使用相同身份验证信息的 IIS 应用程序池。使用相同的身份验证信息在打开模拟的情况下在 php 应用程序目录内创建了一个 web.config 文件。
身份模拟=“true”密码=“ThePass”userName=“TheUser”/>
在 IIS 中的应用程序身份验证中启用了 ASP.NET 模拟。
这一切似乎都不适用于 php 中的这行简单代码:
$dir = opendir("\\someservername\somesharename"); 警告: opendir(\someservername\somesharename) [function.opendir]: 无法打开目录:第 7 行 C:\websites\site\forum\testing.php 中没有错误
因此,我决定使用 ASP.NET 来测试配置。
string[] diretories = System.IO.Directory.GetDirectories("\\someservername\somesharename"); asp.net 测试完美运行。
进一步深入兔子洞,我运行 phpinfo() 并检查其中的用户名信息。在 phpinfo 的“环境”部分中,我找到了“用户名”项。正如我所期望的,它的值是“TheUser”。
一切都表明系统配置正确,直到我尝试:
回显 get_current_user(); 返回的是“IUSR”。这肯定不是我所期望的。
那么,我到底如何让 php + IIS7.5 从国外网络共享中读取数据呢?
更新:
感谢一些答案,我添加了
$result = shell_exec("net use o: \\\\pathToServer\\27301 /persistent:yes 2>&1");
Run Code Online (Sandbox Code Playgroud)
返回成功。我仍然在 opendir 上遇到错误。我尝试了另一个测试并使用 …
我正在使用工作单元模式,该模式在 webapi 请求上执行完所有内容后调用 dbcontext.SaveChanges。在请求的一部分中,我向 dbcontext 添加了一个新客户。
dbContext.Customers.Add(new Customer());
Run Code Online (Sandbox Code Playgroud)
稍后在请求中(通常在域事件处理程序中),我使用相同的 dbcontext 将客户拉回来。
_dbContext.Customers.FirstOrDefault(x => x.Id == id);
public abstract class Customer
{
public Customer()
{
Id = Guid.NewGuid();
}
}
Run Code Online (Sandbox Code Playgroud)
我已经验证 dbContext.Customers.Local 有我期望的对象,但它似乎没有提取本地对象。这可能是因为 Customer 是一个抽象类,由 DirectCustomer 和 InDirectCustomer 实现吗?
为什么?我可以通过配置更改此行为吗?也许我必须合并本地和数据库结果(有点 hacky )。
更新:
class Program
{
static void Main(string[] args)
{
MyDbContext context = new MyDbContext();
Guid customerGuid = Guid.NewGuid();
context.Customers.Add(new DirectCustomer()
{
Id = customerGuid
});
// This does not work, customerFromLocal1 is null
var customerFromLocal1 = context.Customers.FirstOrDefault(x => x.Id …
Run Code Online (Sandbox Code Playgroud) 我正在使用HttpClient从json端点获取对象。提取并订阅可观察对象后,我发现构造函数未在模型上运行,并且对象上的公共方法都未定义。如何使构造函数运行并且方法可用?
export class Customer {
constructor() {
this.Addresses = new Array<Address>();
}
public Addresses: Array<Address>;
public addAddress(address: Address) void{
this.Addresses.push(address);
}
}
var url: string = `${this.urlBase}api/customer/${id}`;
var customerObservable: Observable<Customer> = this.authHttp.get<Customer>(url);
customerObservable.subscribe(customer => {
// Addresses is undefined!
customer.Addresses.push(new Address());
// addAddress is undefined!
customer.addAddress(new Address());
});
Run Code Online (Sandbox Code Playgroud) 我有一个充满表格数据的表格.我需要在表中找到列(单元格)的索引.
例如:
<table>
<tr>
<td>Column1</td>
<td>Column2</td>
<td>Column3</td>
</tr>
<tr>
<td>foo</td>
<td>bar</td>
<td>foobar</td>
</tr>
</table>
function TestIndexOf(someTD)
{
$(someTD) // what's my column index?
}
Run Code Online (Sandbox Code Playgroud) 我有以下谷歌地图的代码.此代码的目的是显示中间带标记的地图.标记是可拖动的,当它被丢弃时,我需要它来提供标记被丢弃的当前Lat/Long.事件并不总是激发.在chrome中,如果我只是让代码运行,它就不起作用.但是,如果我通过调试和停止附加事件的代码来减慢它,那么让它继续,它的工作原理.似乎某处存在竞争条件,但我不知道在哪里.有人可以看看你是否想出一些东西.
function initialize() {
var myOptions = {
zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var canvas = document.getElementById("MapCanvas");
var map = new google.maps.Map(canvas, myOptions);
// Try W3C Geolocation (Preferred)
if (navigator.geolocation) {
browserSupportFlag = true;
navigator.geolocation.getCurrentPosition(function (position) {
initialLocation = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
map.setCenter(initialLocation);
marker = new google.maps.Marker({
position: initialLocation,
draggable: true,
map: map,
title: "You are here"
});
}, function () {
handleNoGeolocation(browserSupportFlag);
});
// Try Google Gears Geolocation
} else if (google.gears) {
browserSupportFlag = true;
var geo = …
Run Code Online (Sandbox Code Playgroud) 我有这个自定义验证属性来验证集合.我需要调整它以使用IEnumerable.我尝试使该属性成为通用属性,但您不能拥有通用属性.
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inherited = true)]
public class CollectionHasElements : System.ComponentModel.DataAnnotations.ValidationAttribute
{
public override bool IsValid(object value)
{
if (value != null && value is IList)
{
return ((IList)value).Count > 0;
}
return false;
}
}
Run Code Online (Sandbox Code Playgroud)
我无法将其转换为IEnumerable,以便我可以检查其count()或any().
有任何想法吗?
c# ×3
.net ×1
angular ×1
google-maps ×1
ienumerable ×1
iis-7.5 ×1
javascript ×1
jquery ×1
php ×1
sockets ×1