在名为"Dev"的表单上,我有以下OnFormClosing函数,以确保在用户关闭表单时正确关闭线程.
protected override void OnFormClosing(FormClosingEventArgs e)
{
base.OnFormClosing(e);
dev.stopMultipleColorsWatcher();
}
Run Code Online (Sandbox Code Playgroud)
如果我直接关闭"开发"表格,工作正常.但是如果"Dev"形式因为主窗体("Form1")被关闭(导致程序退出)而关闭OnFormClosing(),则"Dev"中的函数永远不会被调用,因此线程继续运行并且程序的进程需要通过任务管理器被杀死.
我该如何解决?我意识到我可以OnFormClosing()在"Form1"中添加一个函数,然后OnFormClosing()在"Dev"中调用该函数,但我希望能有一些更干净的东西.
更新:
从主窗体打开开发表单:
private void btn_opendev_Click(object sender, EventArgs e)
{
Dev frm = new Dev();
frm.Show();
}
Run Code Online (Sandbox Code Playgroud)
主窗体真的叫做"programname.UI.Main"(我知道对..),它在"Program.cs"中打开(所以程序的入口点):
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new programname.UI.Main());
}
Run Code Online (Sandbox Code Playgroud) 由于未能使curlppC++工作,我决定开始使用libcurlC代替(现在).对于C和C++来说都是全新的,这有点令人困惑.我甚至不确定我是否可以将C和C++功能分开,但据我所知,这是纯粹的C.
在朋友的帮助下,我设法将输出(curl拾取的页面内容)写入文本文件,但我想将其放在字符串变量中,所以我可以在代码的其他部分使用输出.我可以重新打开文本文件并读取其内容,但这很愚蠢,我想停止写入文件并立即保存到字符串变量.
写功能
/* the function to invoke as the data received */
size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
size_t written;
written = fwrite(ptr, size, nmemb, stream);
return written;
}
Run Code Online (Sandbox Code Playgroud)
整个代码
#include <iostream>
#include "curl/curl.h"
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
/* the function to invoke as the data recieved */
size_t write_data(void *ptr, size_t size, size_t nmemb, FILE *stream) {
size_t written;
written = fwrite(ptr, size, nmemb, stream); …Run Code Online (Sandbox Code Playgroud) 我在这里找到了C#代码
所以我试过了
Public Function checkProperty(ByVal objectt As Object, ByVal propertyy As String) As Boolean
Dim type As Type = objectt.GetType
Return type.GetMethod(propertyy)
End Function
Run Code Online (Sandbox Code Playgroud)
但是,在抛出一个错误type.GetMethod(propertyy)说法"Value of type 'System.Reflection.MethodInfo' cannot be converted to 'Boolean'."
该怎么办?
在我的开发计算机上,一切都工作正常和花花公子,但当我在另一台Windows7计算机上测试程序时,我得到一个System.UriFormatException:无效的URI:字符串中有一个无效的序列.在以下代码中:Uri.UnescapeDataString(section);
起初我以为第二台计算机从dev pc接收不同的数据,所以我复制了失败的html字符串文件并将我的代码减少到:
static void Err(string s){/*Picked up by external logging*/}
private static void GetValue()
{
try
{
var html = File.ReadAllText("ld.txt");
//Retrieve section we want
var section = Regex.Match(
html,
"etc_etc(.*): ",
RegexOptions.Singleline)
.Groups[1].ToString();
Uri.UnescapeDataString(section);
}
catch (Exception ex)
{
Err(ex.ToString());
}
}
Run Code Online (Sandbox Code Playgroud)
在dev pc上正常工作,但第二台计算机再次收到异常.他们都从完全相同的ld.txt文件加载完全相同的html ,然后用它做同样的事情..而且两台PC都是x64 Win7.是什么赋予了?
我的javascript函数只能正确上传文本文件.任何人都可以帮我弄清楚如何使它也接受图像等?
function fileUpload(files) {
if (!files.length) {
fileList.innerHTML = "<p>No files selected!</p>";
} else {
var list = document.createElement("ul");
for (var i = 0; i < files.length; i++) {
//Set vars
var file = files[i],
fileName = file.name,
fileSize = file.size,
fileData = file.getAsBinary(),
boundary = "xxxxxxxxx",
uri = "receive.php",
//Create file info HTML output
li = document.createElement("li");
list.appendChild(li);
var info = document.createElement("span");
info.innerHTML = file.name + ": " + file.size + " bytes";
li.appendChild(info);
//Start sending file
var xhr …Run Code Online (Sandbox Code Playgroud) 我正试图从vb.net转换到C++,我坚持这个.我从这里下载了curlpp,它给了我一个.dll,.exp和.lib文件.我将包含这3个文件的目录添加到项目属性中的"附加库目录"(链接器 - >常规).
接下来,我在项目属性(链接器 - >输入)中添加了ws2_32.lib和Wldap32.lib到"附加依赖项",因为这个问题说明了我应该.
现在我试图让示例00工作,但是
#include <curlpp/curlpp.hpp>
#include <curlpp/Easy.hpp>
#include <curlpp/Options.hpp>
Run Code Online (Sandbox Code Playgroud)
国家"无法打开源文件curlpp/curlpp.hpp"等有意义,因为我从未见过这些文件.我究竟做错了什么?这与vb.net完全不同,我似乎无法弄明白.
更新:
我做了Mat所说的,但它没有用,所以我添加了所有相关文件夹以确定.

但VS仍然说无法找到文件.
我有一个地图,通过他们的ID存储指向对象的指针.
typedef std::map<unsigned int, Entity*> entityMap;
entityMap entitymap;
Run Code Online (Sandbox Code Playgroud)
要为实体分配ID,我可以在entitymap中获取最新值并将其增加1.
Entity *entity = new Entity;
entity->id = /*newest entity+1*/;
entitymap.insert(std::pair<unsigned int,Entity*>(entity->id,entity));
Run Code Online (Sandbox Code Playgroud)
但是这个数字可能变得不必要地大,因为一个实体会被删除并从地图中删除.
std::map<unsigned int,Entity*>::iterator it;
it = entitymap.find(EntityID);
if(it != entitymap.end())
{
Entity *entity= it->second;
entitymap.erase(it);
}
delete entity;
Run Code Online (Sandbox Code Playgroud)
所以我可以拥有一个包含这些值的地图;
1,2,4,8,10
Run Code Online (Sandbox Code Playgroud)
在这种情况下,我希望下一个实体申请该ID 3.
我喜欢使用自解释名称进行关联选择,有时甚至必须避免重复,所以我使用AS关键字很多.但它给我带来了左连接的一些麻烦.
这有效:
$sql = "SELECT *,
projects.id as projects_id
FROM projects";
$sql .= " LEFT JOIN".
" (SELECT
projectfiles.id as projectfiles_id,
projectfiles.fileID as projectfiles_fileID,
projectfiles.projectID as projectfiles_projectID
FROM projectfiles
) AS projectfiles".
" ON projects.id = projectfiles_projectID";
Run Code Online (Sandbox Code Playgroud)
不过现在我结束了与无用的数据projects,因为它也拿起领域userID和name,我不需要.它也是两次获得id.
所以我尝试将其更改为;
$sql = "SELECT
projects.id as projects_id
FROM projects";
Run Code Online (Sandbox Code Playgroud)
随着ON线的成长
" ON projects_id = projectfiles_projectID";
Run Code Online (Sandbox Code Playgroud)
但这给了错误 Unknown column projects_id
所以我试过了
" ON projects.projects_id = projectfiles_projectID";
Run Code Online (Sandbox Code Playgroud)
但仍然是同样的错误
然后我开始尝试,并尝试(作为测试)
$sql = "SELECT id,name,userID FROM projects";
$sql .= " …Run Code Online (Sandbox Code Playgroud) 我的datagridview itemDelete函数:
this.dgv_items.RowsRemoved += this.dgv_items_itemDelete;
private void dgv_items_itemDelete(object sender, DataGridViewRowsRemovedEventArgs e)
{
try
{
int row = e.RowIndex;
string name = dgv_items.Rows[row].Cells[0].Value.ToString();
deleteFromDB(name);
}
catch (Exception) { }
}
Run Code Online (Sandbox Code Playgroud)
但是当我们到达此代码时,该行将被删除,这意味着dgv_items.Rows[row].Cells[0].Value如果行下一行,则获取值.
我想获取已Cells[0]删除行的值,因此我也可以从数据库文件中删除该项.我怎样才能做到这一点?
Libcurl使用以下方法定义电子邮件收件人:
#define RECIPIENT "<bla@bla.com>"
Run Code Online (Sandbox Code Playgroud)
但是,如果我不想对收件人进行硬编码呢?我希望用户能够提供他/她自己的电子邮件地址,所以我需要找到一种方法来执行此操作:
std::string emailreceiver = "bla@bla.com";
#define RECIPIENT = emailreceiver
Run Code Online (Sandbox Code Playgroud)
收件人在此行中使用:
rcpt_list = curl_slist_append(rcpt_list, RECIPIENT);
Run Code Online (Sandbox Code Playgroud)
我假设我不能简单地改变它
std::string emailreceiver = "bla@bla.com";
rcpt_list = curl_slist_append(rcpt_list, emailreceiver);
Run Code Online (Sandbox Code Playgroud)
有人有什么建议吗?