Tag: c ++

如何使用RestSharp发送请求

我试图使用RestSharp客户端POST请求,如下所示我将Auth Code传递给以下函数 public void ExchangeCodeForToken(string code) { if (string.IsNullOrEmpty(code)) { OnAuthenticationFailed(); } else { var request = new RestRequest(this.TokenEndPoint, Method.POST); request.AddParameter(“code”, code); request.AddParameter(“client_id”, this.ClientId); request.AddParameter(“client_secret”, this.Secret); request.AddParameter(“redirect_uri”, “urn:ietf:wg:oauth:2.0:oob”); request.AddParameter(“grant_type”, “authorization_code”); request.AddHeader(“content-type”, “application/x-www-form-urlencoded”); client.ExecuteAsync(request, GetAccessToken); } } void GetAccessToken(IRestResponse response) { if (response == null || response.StatusCode != HttpStatusCode.OK || response.Data == null || string.IsNullOrEmpty(response.Data.access_token)) { […]

在C#和C ++之间共享变量

我正在用c#编写一个软件,它需要多次调用,并且需要多个线程调用c ++非托管dll中的函数。 我有一个这样的C ++文件: // “variables” which consist in some simple variables (int, double) // and in some complex variables (structs containing arrays of structs) extern “C” { __declspec(dllexport) int function1() { // some work depending on random and on the “variables” } } 和那样的C#类 public class class1 { // “variables” <— the "same" as […]

使用C#winform中的app.config访问数据库连接字符串

我似乎无法在我的c#winforms应用程序中访问app.config数据库连接字符串。 app.config代码 C#代码: SqlConnection conn = new SqlConnection(); conn.ConnectionString = System.Configuration.ConfigurationSettings.AppSettings[“MyDBConnectionString”]; 当我尝试C#代码时,我收到一条消息: 警告1’System.Configuration.ConfigurationSettings.AppSettings’已过时:’此方法已过时,已被System.Configuration取代!System.Configuration.ConfigurationManager.AppSettings’ 但是,当我尝试使用时: conn.ConnectionString = System.Configuration!System.Configuration.ConfigurationManager.AppSettings[“MyDBConnectionString”]; 我收到一个错误: 只能将赋值,调用,递增,递减和新对象表达式用作语句

处理Newtonsoft.Json中的十进制值

我有一个MVC应用程序,我在其中处理一些JSON。 这很简单。 我在ModelBinder中有这么简单的代码: return JsonConvert.DeserializeObject(jsonString, bindingContext.ModelType, new JsonSerializerSettings { NullValueHandling = NullValueHandling.Ignore, MissingMemberHandling = MissingMemberHandling.Ignore, Formatting = Formatting.None, DateFormatHandling = DateFormatHandling.IsoDateFormat, FloatParseHandling = FloatParseHandling.Decimal }); 它完美无瑕。 好吧,有点。 假设我有这个课程: public class MyClass { public decimal MyProp { get; set; } } 如果我尝试反序列化这个json: “{\”MyProp\”: 9888.77}” 当然它可以工作,因为9888.77是一个Javascript浮点值。 我认为。 但是我的页面中有一个屏蔽输入,使得JSON看起来像这样(对不起我的英文): “{\”MyProp\”: \”9.888,77\” }” AAAND,它失败了。 它说它Could not convert string to […]

如何在clientSide和ServerSide中使用selectedIndexChanged下拉列表

如何在clientSide和ServerSide中使用asp.net下拉列表中的selectedIndexChanged? 在客户端我想要调用javascript函数! function changeCursor() { document.body.style.cursor=”progress”; } SelectedChange是客户端中的函数名称! 感谢帮助!

获得CPU频率需要一些帮助

我正在尝试制作一个C#软件,它可以读取有关CPU的信息并将其显示给用户(就像CPU-Z一样)。 我目前的问题是我找不到显示CPU频率的方法。 起初我尝试使用Win32_Processor类的简单方法。 它被certificate非常有效,除非CPU超频(或低频)。 然后,我发现我的注册表在HKLM \ HARDWARE \ DESCRIPTION \ System \ CentralProcessor \ 0中包含CPU的“标准”时钟(即使超频)。 问题是在现代CPU中,当CPU不需要它的全功率时,核心乘法器正在减少,因此CPU频率也在变化,但是注册表中的值保持不变。 我的下一步是尝试使用RdTSC来实际计算CPU频率。 我使用C ++是因为如果方法正常,我可以将它嵌入到C#项目中。 我在http://www.codeproject.com/Articles/7340/Get-the-Processor-Speed-in-two-simple-ways找到了下一个代码,但问题是一样的:程序只给我最大频率(就像在注册表值中,1-2 Mhz的差异),它看起来像它加载CPU超过它应该(我甚至有CPU负载峰值)。 #include “stdafx.h” #include #include #include “intrin.h” #include #include float ProcSpeedCalc() { #define RdTSC __asm _emit 0x0f __asm _emit 0x31 // variables for the clock-cycles: __int64 cyclesStart = 0, cyclesStop = 0; // variables for […]

从c#服务器端调用asmx:可以在client元素中找到匹配此契约的端点元素

我在srv1上写了一个asmx webSerivce。 我在srv2上写了一个asp.net (原始文本:一个asp.net)项目的bll项目 。 两者都托管在同一个Web域下 我想从asp.net的bll项目中调用asmx(原文:asp.net(c#)代码)。 1)我添加了一个Web引用,但找不到任何教程如何真正调用引用的服务。 我试过了: private void GetTemplateComponentsData() { var service = new ServiceReference.GetTemplateParamSoapClient(); TemplateParamsKeyValue[] responsArray = service.GetTemplatesParamsPerId(id); foreach (var pair in responsArray) { TemplateComponentsData.Add(pair.Key, pair.Value); } } 但在执行第一行时出现以下错误: 无法在ServiceModel客户端配置部分中找到引用合同“ServiceReference.GetTemplateParamSoap”的默认端点元素。 这可能是因为没有为您的应用程序找到配置文件,或者因为在客户端元素中找不到与此合同匹配的端点元素。 我错过了什么? 2)我将asp.net proj和asmx从一个域迁移到另一个域。 有没有办法相对引用这个webservice?

用大量数据填充DataGridView的最佳方法

我有一个Windows窗体,有两个DataGridViews(DGV),每个将包含25,000多条记录和21列。 我已经使用DataAdapter成功地从数据库加载了数据,然后我尝试使用for循环填充DGV。 每种方法花费的时间大致相同。 第一次将数据填入DGV时需要太长时间(7分钟以上),然后随后的时间更合理(~30秒)。 所以我的问题是,加载具有大量数据的DGV的最佳方法是平均<= 1分钟? 我非常喜欢DGV的功能,但是如果推动推动我愿意使用不同的技术,即使这意味着放弃了一些功能。

从c#调用c ++函数指针

是否可以像这样调用ac(++)静态函数指针(不是委托) typedef int (*MyCppFunc)(void* SomeObject); 来自c#? void CallFromCSharp(MyCppFunc funcptr, IntPtr param) { funcptr(param); } 我需要能够从c#回调到一些旧的c ++类。 C ++是受管理的,但类不是ref类(尚未)。 到目前为止,我不知道如何从c#调用c ++函数指针,这可能吗?

如何通过UTC偏移确定时区?

我有一个场景,我有一个时区偏移(以分钟为单位),需要确定它的时区。 我知道所有数据都不可用(例如,可能有几个时区的偏移量为-240分钟),但“最佳猜测”是可以接受的。 我的第一次传球看起来像这样: foreach (var info in TimeZoneInfo.GetSystemTimeZones()) { if (info.BaseUtcOffset.TotalMinutes == timezoneOffset) { // do something here if this is a valid timezone } } 这种方式有效,但我需要考虑夏令时,这有点让我失望。 我添加了这个可怕的黑客: foreach (var info in TimeZoneInfo.GetSystemTimeZones()) { var extra = info.IsDaylightSavingTime(DateTime.Now) ? 60 : 0; if (info.BaseUtcOffset.TotalMinutes + extra == timezoneOffset) { // do something here if this […]